elsa-workflows / elsa-core

A .NET workflows library
https://v3.elsaworkflows.io/
MIT License
6.5k stars 1.2k forks source link

Error updating to MongoDb latest driver version and Elsa 2.11 #4000

Open alkampfergit opened 1 year ago

alkampfergit commented 1 year ago

Upgrading to latest mongodb driver required by Elsa 2.11 we have problem due to the new LINQ3 provider of 2.19 version of MongoDB C# drivers that is causing serious regressions in the provider. See here to view one of the complaint

Due to this bug actually elsa persistence layer does not work anymore throwing exceptions.

System.InvalidCastException: Unable to cast object of type 'Elsa.Persistence.MongoDb.Serializers.ObjectSerializer' 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()
   at InvokeStub_DiscriminatedInterfaceSerializer`1..ctor(Object, Object, IntPtr*)
   at System.Reflection.ConstructorInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)
   --- End of inner exception stack trace ---
   at System.Reflection.ConstructorInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)
   at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.ConstructorInfo.Invoke(Object[] parameters)
   at MongoDB.Bson.Serialization.BsonSerializationProviderBase.CreateSerializer(Type serializerType, IBsonSerializerRegistry serializerRegistry)
   at MongoDB.Bson.Serialization.BsonSerializationProviderBase.CreateGenericSerializer(Type serializerTypeDefinition, Type[] typeArguments, IBsonSerializerRegistry serializerRegistry)
   at MongoDB.Bson.Serialization.DiscriminatedInterfaceSerializationProvider.GetSerializer(Type type, IBsonSerializerRegistry serializerRegistry)
   at MongoDB.Bson.Serialization.BsonSerializerRegistry.CreateSerializer(Type type)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at MongoDB.Bson.Serialization.BsonSerializerRegistry.GetSerializer(Type type)

Actually to solve the problem we need to let the user to choose to default to old LINQ2 provider and migrate to LINQ3 provider once it will be stable.

alkampfergit commented 1 year ago

Actually there is probably a bug in the new mongodb driver that does not allow registring own ObjectSerializer, because in the LINQ3 provider (LINQ2 is fine) there is an hard cast to MongoDb driver own implementation of ObjectSerializer, I've opened a bug in mongo C# library.

sfmskywalker commented 1 year ago

It looks like this is the same issue as #3975. I'll close the other one since you provided a PR associated with this issue.