Details
-
Bug
-
Resolution: Done
-
Major - P3
-
1.4.2
-
None
-
None
-
Minor Change
Description
Passing C# null to Update.SetWrapped<T> should be valid because T is a POCO and not a BsonValue. A C# null value of T will almost certainly be serialized as a BsonNull.Value (although technically it is up to the serializer for T to decide how to serialize C# null).
To reproduce:
public class C
|
{
|
public ObjectId Id { get; set; }
|
public Point P { get; set; }
|
}
|
|
|
public class Point
|
{
|
public int X { get; set; }
|
public int Y { get; set; }
|
}
|
var doc = new C { P = new Point { X = 1, Y = 2 } };
|
collection.Insert(doc);
|
var id = doc.Id;
|
Console.WriteLine(doc.ToJson());
|
|
|
var query = Query.EQ("_id", id);
|
var update = Update.SetWrapped<Point>("P", null);
|
collection.Update(query, update);
|
|
|
doc = collection.FindOne();
|
Console.WriteLine(doc.ToJson());
|
In 1.4 and later this throws a NullReferenceException. In earlier versions it did not throw a NullReferenceException but it also didn't work.