[CSHARP-4260] Cannot use element name because it is already being used by property Created: 18/Jul/22 Updated: 27/Oct/23 Resolved: 05/Aug/22 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | Serialization |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Blocker - P1 |
| Reporter: | Anup Marwadi | Assignee: | Dmitry Lukyanov (Inactive) |
| Resolution: | Gone away | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
SummaryThe code that has been working for years suddenly started throwing BsonSerializationException after upgrade. Many of our classes simply won't serialize anymore. The details can be found in the additional information section. The errors we get are similar to: MongoDB.Bson.BsonSerializationException: The property 'DateCreatedUtc' of type 'HtComm.Domain.Events.Settings.ThemeSettings' cannot use element name 'DateCreatedUtc' because it is already being used by property 'DateCreatedUtc'. at MongoDB.Bson.Serialization.BsonClassMap.Freeze() at MongoDB.Bson.Serialization.BsonClassMap.LookupClassMap(Type classType) at MongoDB.Bson.Serialization.BsonClassMapSerializationProvider.GetSerializer(Type type, IBsonSerializerRegistry serializerRegistry) Or: There was an error getting Appearance settings.Exception: MongoDB.Bson.BsonSerializationException: Creator map for class HtComm.Domain.Events.Settings.ThemeSettings has 3 arguments, but none are configured. at MongoDB.Bson.Serialization.BsonCreatorMap.Freeze() at MongoDB.Bson.Serialization.BsonClassMap.Freeze()
EnvironmentPlease provide the version of the C / CXX driver. [V2.16.1] Please provide the host OS, version, and architecture (example: Windows 10 64-bit x86). Linux (MongoDB hosted cluster) Please provide the C / CXX compiler and version. .NET 6.0 If applicable, please attach the full output of the cmake command used to configure the C / CXX driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster). replica set How to ReproduceSteps to reproduce. If possible, please include a Short, Self Contained, Correct (Compilable), Example This example here clearly identifies what we are running into. https://www.codewrecks.com/post/general/error-in-mongodb-serializer/ I can also provide additional Gists if needed Additional BackgroundWe were on version 2.11.6 and hadn't upgraded the nuget packages to the latest. Upon upgrading to the latest, i.e. 2.16.1, we started noticing a lot of serialization errors related to BsonClassMap.Freeze() After checking the logs, the exact version where these errors started is 2.12.0. Many of the erroring classes compile fine on 2.11.6, but fail starting 2.12.0. |
| Comments |
| Comment by PM Bot [ 05/Aug/22 ] |
|
There hasn't been any recent activity on this ticket, so we're resolving it. Thanks for reaching out! Please feel free to comment on this if you're able to provide more information. |
| Comment by Dmitry Lukyanov (Inactive) [ 21/Jul/22 ] |
|
Thanks anup@hypertrends.com for your report, can you please provide a reproduction of your case, the link your provided contains a different case. |
| Comment by Anup Marwadi [ 18/Jul/22 ] |
|
It should be noted that majority of these errors go away when the property setters are made public instead of private or protected. While this is inconvenient and breaks encapsulation in our code designs, we have been able to at least spend a few days to identify impacted areas and fix
|