[CSHARP-1475] NullReferenceException when [BsonConstructor] is used with bad parameter name Created: 12/Nov/15  Updated: 30/Nov/16  Resolved: 30/Nov/16

Status: Closed
Project: C# Driver
Component/s: Serialization
Affects Version/s: 1.10.1
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Robert Stam Assignee: Unassigned
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related

 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.



 Comments   
Comment by Robert Stam [ 30/Nov/16 ]

Since this bug only exists in 1.11 and 1.11 is effectively at end of life I'm closing this ticket as won't fix.

Generated at Wed Feb 07 21:39:42 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.