Datastax C# Driver .Build() Throws System.IO.FileLoadException

95 views Asked by At

looks like I have a binding redirects issue that I don't know how to solve.

When .Build() is called, I get the following exception:

[2020-10-09 14:09:28.806] [                              :001] [ERROR] [DatabaseClient                ] Failed to connect to Cassandra Database...
System.IO.FileLoadException: Could not load file or assembly 'System.Threading.Tasks.Dataflow, Version=4.6.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'System.Threading.Tasks.Dataflow, Version=4.6.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
   at Cassandra.ProtocolEvents.ProtocolEventDebouncer..ctor(ITimerFactory timerFactory, TimeSpan delay, TimeSpan maxDelay)
   at Cassandra.Cluster..ctor(IEnumerable`1 contactPoints, Configuration configuration)
   at Cassandra.Cluster.BuildFrom(IInitializer initializer, IReadOnlyList`1 nonIpEndPointContactPoints, Configuration config)
   at OpportunityRecorder.DatabaseClient.<ConnectToCassandraAsync>d__12.MoveNext() in C:\Gitlab-Runner\builds\4Gddire9\0\dev\V\OpportunityRecorder\OpportunityRecorder\DatabaseClient.cs:line 46

I have another project in this solution that references System.Threading.Tasks.Dataflow, Version=4.11.1.0.

This error doesn't happen locally, but happens when I deploy my application.

How can I fix this?

2

There are 2 answers

0
João Reis On

Can you try installing System.Threading.Tasks.Dataflow, Version=4.11.1.0 in the project that uses the DataStax driver?

0
AudioBubble On

Looks like there were two assemblies being references by the same set of projects, but with different versions. What I did was add both <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> and <PreserveCompilationContext>true</PreserveCompilationContext> to my .csproj file for my StartUp (main) project. This generated a binding reference in my App.config that would point all earlier versions of the assembly to a single version amongst all projects.

enter image description here