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

For GuidRepresentationMode.V3, an exception is thrown when saving an ExpandoObject with a Guid

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Works as Designed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Serialization
    • Labels:
      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)
       
       
      
      

        Attachments

          Activity

            People

            Assignee:
            james.kovacs James Kovacs
            Reporter:
            m.wildgruber@sevantage.de Markus Wildgruber
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: