-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
Unknown
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
I have a thread in the MongoDB forum for this here: https://www.mongodb.com/community/forums/t/dynamic-variables-are-causing-issues/242663/4
To put the details here; I’m using MongoDB.Driver 2.21.0 in my .NET 7 API. I am trying to use reflection to dynamically return data.
When I use `
Builders<BsonDocument>.Filter.In(field, values)`, if `field` property is a string or int, `values` can be
new List<dynamic> { "some", "strings", "here" }
or
new List<dynamic> { 1, 2, 3 }
and it correctly returns any documents that contain those values. But, if `field` is a Guid and `values` is
new List<dynamic> { Guid.Parse("6cd6f392-8271-49bb-8564-e584ddf48890"), Guid.Parse("c7b1ebaf-4ac1-4fe0-b066-1282e072585a") })
, then I get this error:
MongoDB.Bson.BsonSerializationException: GuidSerializer cannot serialize a Guid when GuidRepresentation is Unspecified.
Even though in my Program.cs, I have the Guid representation set.
BsonDefaults.GuidRepresentationMode = GuidRepresentationMode.V3; BsonSerializer.RegisterSerializer(new GuidSerializer(GuidRepresentation.Standard));
If `values` is
new List<Guid> { Guid.Parse("6cd6f392-8271-49bb-8564-e584ddf48890"), Guid.Parse("c7b1ebaf-4ac1-4fe0-b066-1282e072585a") });
It correctly returns any documents that have that Guid in the `field`. The only difference is `List<dynamic>` vs `List<Guid>`. But in my case, it needs to be dynamic as I am using input to figure out what documents to filter out.
- is related to
-
CSHARP-4987 Guid serialization not standardized
-
- Closed
-