c# - RabbitMQ 连接工厂在我的应用程序箱中找不到 System.Threading.Tasks.Extensions

标签 c# rabbitmq assembly-binding-redirect .net-4.8 assemblybinding

我有以下代码

var factory = new ConnectionFactory()
{
    HostName = "path.to.host.net",
    UserName = "guest",
    Password = "guest",
    VirtualHost = "myhost"
};
var connection = factory.CreateConnection();

上面的最后一行报错如下

FileLoadException: Could not load file or assembly 'System.Threading.Tasks.Extensions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

我检查了 Fusion Log,它说了以下内容

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 Disassembler 中打开了 bin 中的 DLL,并检查了 list ,发现了以下内容

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 不匹配,所以我决定添加以下绑定(bind)重定向

<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。我错过了什么?

最佳答案

clr 会忽略重复的绑定(bind)重定向。

这很尴尬。

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

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

关于c# - RabbitMQ 连接工厂在我的应用程序箱中找不到 System.Threading.Tasks.Extensions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66066987/

相关文章:

c# - Linq 返回字符串数组

c# - 转换日期时转换失败 - linq2sql ExecuteQuery

c# - ASP.NET MVC 需要两个不同版本的 Newtonsoft.Json.dll

c# - 如何将程序集绑定(bind)重定向到当前版本或更高版本?

c# - 从 DataTable 填充类

c# - 编译器如何处理带有后缀运算符的 return 语句?

rabbitmq - 在运行 rabbitmq 的 docker 容器上远程创建 vhost

python - RabbitMQ - Python/Pika 如何知道队列是否为空?

node.js - Rabbit MQ amqplib错误 "No channels left to allocate"

F# 类型提供程序依赖项解析 - "Could not load file or assembly..."