Details
-
Task
-
Resolution: Works as Designed
-
Major - P3
-
None
-
None
-
None
Description
When saving an ExpandoObject that contains a GUID property, GuidSerializer throws an exception if BsonDefaults.GuidRepresentationMode = GuidRepresentationMode.V3.
See this code: mongo-csharp-driver/GuidSerializer.cs at master · mongodb/mongo-csharp-driver (github.com)
Exception is thrown at line 174:
throw new BsonSerializationException("GuidSerializer cannot serialize a Guid when GuidRepresentation is Unspecified."); |
The following code reproduces the issue:
BsonDefaults.GuidRepresentationMode = GuidRepresentationMode.V3;
|
var client = new MongoClient("mongodb://localhost:27017"); |
var db = client.GetDatabase("test"); |
var coll = db.GetCollection<ExpandoObject>("expando"); |
var exp = new ExpandoObject(); |
((IDictionary<string, object>)exp)["MyGuid"] = Guid.NewGuid(); |
await coll.InsertOneAsync(exp);
|
If the first line is omitted, the expandoobject is serialized and saved to db, but not as a UUID, but as binary, e.g.
Binary('RlOOu1meGkOh0ZMoDqcAiA==', 3) |
|
|
|
|
|