Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-4784

List<dynamic> does not work when Guids.

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?
    • None
    • None
    • None
    • None
    • 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.
       

            Assignee:
            ferdinando.papale@mongodb.com Ferdinando Papale
            Reporter:
            stevens.rothwell@gmail.com Steven Rothwell
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: