Datastax C#驱动程序.Build引发System.IO.FileLoadException

问题描述

看起来我有一个绑定重定向问题,我不知道如何解决

调用.Build()时,出现以下异常:

[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,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

解决方案中的另一个项目引用了System.Threading.Tasks.Dataflow,Version=4.11.1.0

错误不是在本地发生,而是在我部署应用程序时发生。

我该如何解决

解决方法

您可以尝试在使用DataStax驱动程序的项目中安装System.Threading.Tasks.Dataflow,Version=4.11.1.0吗?

,

看起来有两个程序集被同一组项目引用,但是版本不同。我所做的就是将 <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> <PreserveCompilationContext>true</PreserveCompilationContext>都添加到我的Start(主)项目的.csproj文件中。这在我的App.config中生成了一个绑定引用,该引用将程序集的所有早期版本指向所有项目中的单个版本。

enter image description here