Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MorestachioFormatterService is not thread safe #21

Closed
WizX20 opened this issue Apr 29, 2022 · 3 comments
Closed

MorestachioFormatterService is not thread safe #21

WizX20 opened this issue Apr 29, 2022 · 3 comments

Comments

@WizX20
Copy link

WizX20 commented Apr 29, 2022

Describe the bug
The MorestachioFormatterService is not thread safe.

To Reproduce

XXX threw exception: 
System.TypeInitializationException: The type initializer for 'Morestachio.Formatter.Framework.MorestachioFormatterService' threw an exception. ---> System.TypeInitializationException: The type initializer for 'Morestachio.Formatter.Predefined.Accounting.CurrencyHandler' threw an exception. ---> System.ArgumentException: An item with the same key has already been added. Key: PYG
  Stack Trace:
      at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
   at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
   at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
   at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector)
   at Morestachio.Formatter.Predefined.Accounting.CurrencyHandler..cctor()
--- End of inner exception stack trace ---
    at Morestachio.Formatter.Predefined.Accounting.CurrencyHandler.get_DefaultHandler()
   at Morestachio.Formatter.Framework.MorestachioFormatterService..cctor()
--- End of inner exception stack trace ---
    at Morestachio.Formatter.Framework.MorestachioFormatterService..ctor(Boolean useCache)
   at Morestachio.ParserOptions..ctor(ITemplateContainer template, Func`2 sourceStream, Encoding encoding)
   at Morestachio.ParserOptions..ctor(ITemplateContainer template, Func`1 sourceStream, Encoding encoding)
   at Morestachio.ParserOptions..ctor(String template, Func`1 sourceStream, Encoding encoding)
   at Morestachio.ParserOptions..ctor(String template, Func`1 sourceStream)
   at Morestachio.ParserOptions..ctor(String template)

Expected behavior
Should use thread safe collections internally: https://docs.microsoft.com/en-us/dotnet/standard/collections/thread-safe/

@JPVenson
Copy link
Owner

That does not look like a thread problem to me, more like a duplicate in the currency map.

@JPVenson
Copy link
Owner

Hotfix is released by version 5.0.1.577. Could you please verify?

@WizX20
Copy link
Author

WizX20 commented Apr 29, 2022

Tested and deemed working! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants