-
Type:
Bug
-
Resolution: Works as Designed
-
Priority:
Minor - P4
-
None
-
Affects Version/s: 2.4.2
-
Component/s: Serialization
-
None
-
Environment:VS2015
-
None
-
None
-
None
-
None
-
None
-
None
-
None
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):
public void TriggerUserBug() { var connection = ConfigurationManager.AppSettings["MongoDBConnection"]; var database = ConfigurationManager.AppSettings["DatabaseName"]; var client = new MongoClient(connection); IMongoDatabase db = client.GetDatabase(database); IMongoCollection<User> collection = db.GetCollection<User>("users"); var filter = Builders<User>.Filter.Eq("_id", ObjectId.Parse("533ab4de616c6565c9bc0000")); var result = collection.Find(filter).FirstOrDefault(); // generates the exception Assert.AreEqual("533ab4de616c6565c9bc0000", result.Id.ToString()); }
The User object declares the sub-document like this:
[BsonElement("settings")] public BsonDocument Settings { get; set; }
The string "admin" does not appear in the code at all.
The data in the MongoDB sub-document looks like:
"settings" : { "admin" : { "ext_number" : "999" } },
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).