[CSHARP-4565] [BsonSerializer] property attribute with custom dictionary breaks in 2.19 Created: 09/Mar/23 Updated: 27/Oct/23 Resolved: 23/Mar/23 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | None |
| Affects Version/s: | 2.19.0 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Minor - P4 |
| Reporter: | Tim Arheit | Assignee: | Robert Stam |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Documentation Changes Summary: | 1. What would you like to communicate to the user about this feature? |
| Description |
|
In version 2.18 (and before) we used a property attribute to define a custom dictionary serializer as below: [BsonSerializer(typeof(CustomDictionarySerializer<Dictionary<AccountConfigType, string>, EnumStringSerializer<AccountConfigType>, CustomObjectSerializer<string>>))] But after upgrading to 2.19, we would get the error: System.TypeInitializationException : The type initializer for 'i3vDB.Collections.Account' threw an exception.
Removing the property attribute, and instead using the below fixes the issue. BsonSerializer.RegisterGenericSerializerDefinition(typeof(Dictionary<AccountConfigType, string>), typeof(CustomDictionarySerializer<Dictionary<AccountConfigType, string>, EnumStringSerializer<AccountConfigType>, CustomObjectSerializer<string>>));
I should also note that if you have both the property attribute and the explicit registration, it throws the same exception. I did not test any other custom serializers as we didn't have any others specified by property attribute. I don't know if it's significant as it could just be caused by the exception output, but the TYPE X doesn't match TYPE X message only differs in Lib.Shared. The second instance is in quotes and has a space at the end. They are otherwise identical. |
| Comments |
| Comment by Robert Stam [ 23/Mar/23 ] |
|
Thank you for letting us know that you figured out the issue. I will go ahead and close this issue. |
| Comment by Tim Arheit [ 13/Mar/23 ] |
|
Tracked the issue down to a trailing space in the assembly name. Not sure why it didn't show up before. |