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

NullReferenceException when [BsonConstructor] is used with bad parameter name

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: Minor - P4 Minor - P4
    • None
    • 1.10.1
    • Serialization
    • None

    Description

      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.

      Attachments

        Activity

          People

            Unassigned Unassigned
            robert@mongodb.com Robert Stam
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: