[CSHARP-1280] Deserializing fails if a document contains unmapped field which name starts with the same name as currently mapped class property. Created: 14/May/15  Updated: 14/May/15  Resolved: 14/May/15

Status: Closed
Project: C# Driver
Component/s: Serialization
Affects Version/s: 2.0
Fix Version/s: 2.0.1

Type: Bug Priority: Major - P3
Reporter: Yuriy Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows


Attachments: Zip Archive MongoDriverBug.zip    
Issue Links:
Duplicate
duplicates CSHARP-1255 An ignored BsonElement with a prefix ... Closed

 Description   

Consider a situation when you have a class with a property named "Abc". You stored an object of this class in Mongo. Later you decide to rename the property to "Abcd" (notice that the new property name starts with the same letters as the old one). Now if you try to deserialize the previously saved document (which contains the old key called "Abc"), the deserialization fails inside the BsonStreamExtensions.ReadBsonType method. This happens even if SetIgnoreExtraElements is set to true.

There are two different exceptions thrown inside the BsonStreamExtensions.ReadBsonType method depending whether the new ("Abcd") key is stored in the document or not. If it is stored, the method will fail with FormatException ("Invalid BsonType"). It it's not stored, then it fails with System.IO.EndOfStreamException.

I'm attaching a sample solution with instructions how to reproduce the bug in comments.



 Comments   
Comment by Yuriy [ 14/May/15 ]

Thank you for the quick resolution!
Hopefully 2.0.x is coming out soon...

Comment by Robert Stam [ 14/May/15 ]

Thanks for the helpful reproduction instructions. They made it easy to verify that this has already been fixed.

Comment by Robert Stam [ 14/May/15 ]

I verified that this issue is resolved in both the master and the 2.0.x branches by the fix to CSHARP-1255.

Comment by Robert Stam [ 14/May/15 ]

This appears to be at least partially related to CSHARP-1255.

Generated at Wed Feb 07 21:39:09 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.