[CSHARP-479] Array serialization options for items are not always being used at deserialization time Created: 29/May/12  Updated: 02/Apr/15  Resolved: 29/May/12

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: 1.4.2
Fix Version/s: 1.5

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

Issue Links:
Depends

 Description   

To reproduce use this class:

public class C
{
    public ObjectId Id;
    [BsonRepresentation(BsonType.ObjectId)] // applies to items not to array
    public string[] X;
}

and this code:

var c = new C { X = new string[] { ObjectId.GenerateNewId().ToString(), ObjectId.GenerateNewId().ToString() } };
var json = c.ToJson();
Console.WriteLine(json);
 
var d = BsonSerializer.Deserialize<C>(json); // throws exception because of this bug
Console.WriteLine(d.ToJson());


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