-
Type: Bug
-
Resolution: Fixed
-
Priority: Unknown
-
Affects Version/s: None
-
Component/s: None
-
None
-
Fully Compatible
-
Not Needed
-
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.