RabbitMQ连接工厂无法在我的应用程序bin中找到系统.线程.任务.扩展

a0x5cqrl  于 2022-11-08  发布在  RabbitMQ
关注(0)|答案(3)|浏览(153)

我有下面的代码

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

上面的最后一行抱怨了以下错误
文件加载异常:未能加载文件或程序集“System.Threading.Tasks.Extensions,Version=4.2.0.0,Culture=neutral,PublicKeyToken=cc7b13ffcd2ddd51”或它的某个依赖项。找到的程序集的清单定义与程序集引用不匹配。(HRESULT异常:0x80131040)中的一个值
我检查了融合日志,它显示以下内容

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,并检查了清单,发现了以下内容
上述4.2.0.1内容依赖于系统.运行时.编译器服务.不安全的4.0.4.1,该文件已经在bin中。
因此,4.2.0.0与www.example.com不匹配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>

我仍然得到相同的运行时错误抱怨,它没有找到扩展4. 2. 0. 0。我错过了什么?

ih99xse1

ih99xse11#

clr会忽略重复的系结重新导向。

这太尴尬了。
我发现对于同一个System.Threading.Tasks.Extensions程序集有两个绑定重定向,系统使用了找到的第一个,忽略了第二个。并且没有关于重复的抱怨。
希望这个答案将来能保存别人的时间。

wsxa1bj1

wsxa1bj12#

在我的例子中,我降级到System.Threading.Tasks.Extensions 4. 5. 3版本。由于某种原因,微软将此dll与nuget中的版本放在了不同的程序集版本中。

chy5wohz

chy5wohz3#

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

相关问题