Details
-
Bug
-
Resolution: Won't Fix
-
Unknown
-
None
-
None
-
None
-
None
Description
The following should reproduce a MongoDB.Bson.BsonSerializationException on update.
// — Model:
public class Test
{ [BsonId] public object Id \{ get; set; }= ObjectId.GenerateNewId();
public string Name { get; set; }
public byte[] Data { get; set; }
public BsonDocument Doc { get; set; }
public static IMongoCollection<Test> GetCollection()
}
// — Code:
var t = new Test();
t.Name = "TestName";
t.Doc = new BsonDocument();
t.Doc["Name"] = "TestDocName";
await c.InsertOneAsync(t, cancellationToken: cancellationToken);
string? nullString = null;
await c.UpdateOneAsync(
d => d.Id == t.Id,
Builders<Test>.Update
.Set(d => d.Data, null)
.Set("Name", nullString)
.Set("Doc.Name", nullString), // <-- Source of error
cancellationToken: cancellationToken);
MongoDB.Bson.BsonSerializationException: 'C# null values of type 'BsonValue' cannot be serialized using a serializer of type 'BsonValueSerializer'.'