NullReferenceException when [BsonConstructor] is used with bad parameter name

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Won't Fix
    • Priority: Minor - P4
    • None
    • Affects Version/s: 1.10.1
    • Component/s: Serialization
    • None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Consider the following simple immutable class that uses the [BsonConstructor] attribute to configure class map based serialization:

      public class C
      {
          private readonly int _x;
      
          [BsonConstructor]
          public C(int x)
          {
              _x = x;
          }
      
          [BsonElement]
          public int X
          {
              get { return _x; }
          }
      }
      

      The constructor argument "x" is matched with the property "X" (using case insensitive matching).

      Now consider the following variation of the constructor which compiles correctly but doesn't work for deserialization:

      [BsonConstructor]
      public C(int y)
      {
          _x = y;
      }
      

      In this case, the constructor argument "y" can't be matched with any property, so this is an error.

      Currently the driver is throwing a NullReferenceException when a constructor parameter can't be matched with a property. It should throw a more informative exception.

            Assignee:
            Unassigned
            Reporter:
            Robert Stam (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: