[CSHARP-1392] NullReferenceException thrown when deserializing an immutable class with an extra elements property Created: 31/Aug/15  Updated: 20/Jan/16  Resolved: 01/Sep/15

Status: Closed
Project: C# Driver
Component/s: Serialization
Affects Version/s: 2.0.1
Fix Version/s: 2.1

Type: Bug Priority: Major - P3
Reporter: Robert Stam Assignee: Robert Stam
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 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);



 Comments   
Comment by Githook User [ 01/Sep/15 ]

Author:

{u'username': u'rstam', u'name': u'rstam', u'email': u'robert@robertstam.org'}

Message: CSHARP-1392: Added tests for partially immutable class scenario.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/2560b61f35341cd3069c57859585006dfef6c917

Comment by Githook User [ 01/Sep/15 ]

Author:

{u'username': u'rstam', u'name': u'rstam', u'email': u'robert@robertstam.org'}

Message: CSHARP-1392: Support ExtraElements property in immutable classes.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/eadcb9dd8d51f3ac5d1ba48cc2c3e2e6f4f5538e

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