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

ContainsKey throws an exception when key is not a string but is serialized as a string

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 2.22.0
    • Affects Version/s: 2.20.0
    • Component/s: LINQ3
    • None
    • Fully Compatible
    • Not Needed
    • 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?

      Summary

      Since changing the version of the LINQ driver to v3 we receive this error, in v2 everything was working fine. The main problem seems to be that the key of the dictionary is a enum (which is mapped to a string with a RegisterClassMap).

      How to Reproduce

      Query: 

      Collection.AsQueryable<Translation>.Where(x => x.Languages.ContainsKey(language)).ToListAsync(token);

       

      Mapping:

       

                BsonClassMap.RegisterClassMap<Translation>(doc =>
                  {
                      doc.AutoMap();
                      doc.SetIgnoreExtraElements(true);
                      doc.MapIdMember(a => a.Id)
                          .SetIdGenerator(new StringObjectIdGenerator())
                          .SetSerializer(new StringSerializer(BsonType.ObjectId));
                      doc.MapMember(a => a.Languages)
                          .SetSerializer(new DictionaryInterfaceImplementerSerializer<Dictionary<Languages, string>>(
                              DictionaryRepresentation.Document, new EnumSerializer<Languages>(BsonType.String), new StringSerializer()
                          ));
                  });
      

       

       

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            brecht.vanhaesebrouck@sea-invest.com Brecht Vanhaesebrouck
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: