RabbitMQ连接工厂在我的应用程序bin中找不到System.Threading.Tasks.Extensions。

3
我有以下代码。
var factory = new ConnectionFactory()
{
    HostName = "path.to.host.net",
    UserName = "guest",
    Password = "guest",
    VirtualHost = "myhost"
};
var connection = factory.CreateConnection();

以上代码的最后一行提示以下错误:

FileLoadException: 无法加载文件或程序集'System.Threading.Tasks.Extensions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'或其某个依赖项。所定位的程序集清单定义与程序集引用不匹配。(HRESULT 异常:0x80131040)

我检查了Fusion日志,结果如下:
Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  C:\Program Files (x86)\IIS Express\iisexpress.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: DisplayName = System.Threading.Tasks.Extensions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
 (Fully-specified)
LOG: Appbase = file:///C:/Path/To/Web/
LOG: Initial PrivatePath = C:\Path\To\\Web\bin
Calling assembly : System.Threading.Channels, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Path\To\Web\web.config
LOG: Using host configuration file: C:\Users\fahadash\Documents\IISExpress\config\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: System.Threading.Tasks.Extensions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
LOG: Attempting download of new URL file:///C:/Users/fahadash/AppData/Local/Temp/Temporary ASP.NET Files/vs/699f3d52/97d4d2c/System.Threading.Tasks.Extensions.DLL.
LOG: Attempting download of new URL file:///C:/Users/fahadash/AppData/Local/Temp/Temporary ASP.NET Files/vs/699f3d52/97d4d2c/System.Threading.Tasks.Extensions/System.Threading.Tasks.Extensions.DLL.
LOG: Attempting download of new URL file:///C:/Path/To/Web/bin/System.Threading.Tasks.Extensions.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Revision Number
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

我在IL反汇编器中打开了bin文件夹中的DLL,并检查了清单,发现如下信息:

System.Threading.Tasks.Extensions.DLL 版本为 4.2.0.1。 该版本依赖于 System.Runtime.CompilerServices.Unsafe 4.0.4.1,而此版本已经存在于 bin 文件夹中。

因此,由于 4.2.0.0 与 4.2.0.1 不匹配,我决定添加以下绑定重定向:

<dependentAssembly>
  <assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
  <bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" />
</dependentAssembly>

我仍然收到相同的运行时错误,它抱怨没有找到Extensions 4.2.0.0。我错过了什么?
3个回答

2

CLR会忽略重复的绑定重定向。

这很尴尬。

我发现我为同一个System.Threading.Tasks.Extensions程序集有两个绑定重定向,系统使用找到的第一个并忽略第二个。而且没有关于重复的投诉。

希望这个答案能够节省其他人的时间。


1
哎呀,这个问题已经困扰我好几个小时了。我的配置文件中没有重复项,但是我一直在尝试找出为什么 System.Threading.Channels 调用的是 .0 版本,而我们在构建目录中得到的是 .1 版本。真是超级烦人啊。绑定重定向在可插拔基础设施中确实很麻烦。不过,这让我遇到了下一个问题。谢谢! - TravisWhidden
@TravisWhidden,您能否发布一个答案,包括您的情况有何不同? - fahadash

1

在我的情况下,我将 System.Threading.Tasks.Extensions 版本降级至 4.5.3。由于某些原因,微软将此 dll 与 nuget 中的版本放在了不同的程序集版本中。


-2

在C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config中添加绑定重定向。这对我很有效,但我不知道如何在生产中使用它...


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接