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

NullReferenceException thrown when deserializing an immutable class with an extra elements property

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 2.0.1
    • Fix Version/s: 2.1
    • Component/s: Serialization
    • Labels:
      None
    • Sprint:
      C# Sprint 24

      Description

      Given the following immutable class:

      public class C
      {
          [BsonElement]
          public int X { get; }
          [BsonExtraElements]
          [BsonDefaultValue(null)]
          public BsonDocument E { get; }
       
          [BsonConstructor]
          public C(int x, BsonDocument e)
          {
              X = x;
              E = e;
          }
      }
      

      Attempting to deserialize a document with an extra element throws a NullReferenceException.

      To reproduce:

      var json = "{ X : 1, Y : 2 }";
      var c = BsonSerializer.Deserialize<C>(json);
      

        Attachments

          Activity

            People

            Assignee:
            rstam Robert Stam
            Reporter:
            rstam Robert Stam
            Participants:
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: