You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We sometimes see bizarre exceptions when trying to build custom class maps like this:
System.InvalidCastException: Unable to cast object of type 'CsvHelper.Configuration.MemberMap`2[SomeModelClass,System.Int32]' to type 'CsvHelper.Configuration.MemberMap`2[SomeOtherModelClass,System.DateOnly]'.
Once a process starts throwing these exceptions it seems to be permanent and the only fix is to kill the process.
To Reproduce
Intermittent thread safety issues are very difficult to reliably reproduce.
Expected behavior
ObjectResolver appears to have inconsistent locking in the default configuration.
The default instance uses an object local to the static constructor for locking:
Additional context
Our application often receives many requests in parallel so it is very possible for there to be multiple requests trying to build class maps for the first time at the same time.
The text was updated successfully, but these errors were encountered:
I dug into trying to reproduce this today and after several maddening hours, I'm convinced that it is not a thread safety issue, since I was unable to write any code that hit the non-locked calls to ObjectCreator.
However, there is another possibility (which is even harder to reproduce, of course):
Describe the bug
We sometimes see bizarre exceptions when trying to build custom class maps like this:
Once a process starts throwing these exceptions it seems to be permanent and the only fix is to kill the process.
To Reproduce
Intermittent thread safety issues are very difficult to reliably reproduce.
Expected behavior
ObjectResolver appears to have inconsistent locking in the default configuration.
The default instance uses an object local to the static constructor for locking:
CsvHelper/src/CsvHelper/ObjectResolver.cs
Lines 56 to 67 in d0b6e3b
But then later in the class
objectCreator.CreateInstance
is called without the locking:CsvHelper/src/CsvHelper/ObjectResolver.cs
Lines 107 to 120 in d0b6e3b
And indeed ObjectCreator has a cache that is not thread safe:
CsvHelper/src/CsvHelper/ObjectCreator.cs
Line 16 in d0b6e3b
Screenshots
n/a
Additional context
Our application often receives many requests in parallel so it is very possible for there to be multiple requests trying to build class maps for the first time at the same time.
The text was updated successfully, but these errors were encountered: