-
Type: Bug
-
Resolution: Duplicate
-
Priority: Major - P3
-
Affects Version/s: 2.0
-
Component/s: Serialization
-
None
-
Environment:Windows
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.
- duplicates
-
CSHARP-1255 An ignored BsonElement with a prefix of a known BsonElement's causes an EndOfStreamException
- Closed