Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-1280

Deserializing fails if a document contains unmapped field which name starts with the same name as currently mapped class property.

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • 2.0.1
    • Affects Version/s: 2.0
    • Component/s: Serialization
    • Labels:
      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.

            Assignee:
            Unassigned Unassigned
            Reporter:
            yuriylsh Yuriy
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: