[CSHARP-1933] Mapping a sub-document throws System.FormatException with a duplicate element name Created: 06/Mar/17 Updated: 27/Oct/23 Resolved: 07/Mar/17 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | Serialization |
| Affects Version/s: | 2.4.2 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Minor - P4 |
| Reporter: | Huw Leonard [X] | Assignee: | Robert Stam |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
VS2015 |
||
| Description |
|
An exception of type System.FormatException is thrown, with the following description: Additional information: An error occurred while deserializing the Settings property of class Application.Models.User: Duplicate element name 'admin'. The offending code (a test case created to trigger the bug in isolation):
The User object declares the sub-document like this:
The string "admin" does not appear in the code at all. The data in the MongoDB sub-document looks like:
The string "admin" does not appear anywhere else in the user document (which is very large, which is why I haven't included it here). |
| Comments |
| Comment by Huw Leonard [X] [ 07/Mar/17 ] | |||||||||||||||||||||||||||||||||||||||
|
That would certainly explain the situation, as well as why created test data doesn't trigger the same result. The data was originally created via mongoid, so I imagine that that behaves differently than the C# driver as well. It seems that this is not a bug per se, so thanks for clearing it up. | |||||||||||||||||||||||||||||||||||||||
| Comment by Robert Stam [ 07/Mar/17 ] | |||||||||||||||||||||||||||||||||||||||
|
It's probable that your document stored in the database really does have a duplicate element. But it occurs to me that if you are looking at the documents using the shell you won't be able to see that. The shell reacts to documents with duplicate documents differently than the C# driver does. If the shell sees a document with duplicate elements the second one simply overwrites the first one. | |||||||||||||||||||||||||||||||||||||||
| Comment by Robert Stam [ 06/Mar/17 ] | |||||||||||||||||||||||||||||||||||||||
|
I am unable to reproduce this. I adapted the code you provided to a standalone console application. Let me know if you think I need to do something different to reproduce.
|