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

Error in LINQ3 provider when custom ObjectSerializer is used

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Unknown Unknown
    • 2.19.2
    • None
    • None
    • 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?

    Description

      Summary

      version 2.19 of C# Driver.

      With new LINQ3 provider, if you use a custom ObjectSerializer like Elsa does (https://github.com/elsa-workflows/elsa-core/blob/047c51d7cf7b8a3230353e3518439704756ca95b/src/persistence/Elsa.Persistence.MongoDb/Serializers/ObjectSerializer.cs) you incurr in an error when you execute any LINQ query based on new LINQ3 provider

       ---> System.InvalidCastException: Unable to cast object of type 'Elsa.Persistence.MongoDb.Serializers.ElsaObjectSerializer' to type 'MongoDB.Bson.Serialization.Serializers.ObjectSerializer'.
         at MongoDB.Bson.Serialization.Serializers.DiscriminatedInterfaceSerializer`1..ctor(IDiscriminatorConvention discriminatorConvention, IBsonSerializer`1 interfaceSerializer)
         at MongoDB.Bson.Serialization.Serializers.DiscriminatedInterfaceSerializer`1..ctor(IDiscriminatorConvention discriminatorConvention)
         at MongoDB.Bson.Serialization.Serializers.DiscriminatedInterfaceSerializer`1..ctor()

      How to Reproduce

      It is sufficient to declare a custom object serializer, like elsa does (https://github.com/elsa-workflows/elsa-core/blob/047c51d7cf7b8a3230353e3518439704756ca95b/src/persistence/Elsa.Persistence.MongoDb/Serializers/ObjectSerializer.cs) register the serializer, persists some objects and then issue a LINQ query to retrieve. If you look at the attached image, in the constructor of  DiscriminatedInterfaceSerializer class, the driver is looking for MongoDb serializer for object but it CAST immeditaly to ObjectSerializer, thus preventing anyone from registering own serializer for object class.

      Additional Background

      Look at attached image.

      Attachments

        Activity

          People

            oleksandr.poliakov@mongodb.com Oleksandr Poliakov
            alkampfer@nablasoft.com Gian Maria Ricci
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: