问题描述
var factory = new ConnectionFactory()
{
HostName = "path.to.host.net",UserName = "guest",Password = "guest",VirtualHost = "myhost"
};
var connection = factory.CreateConnection();
FileLoadException: 无法加载文件或程序集 'System.Threading.Tasks.Extensions,版本=4.2.0.0,文化=中性, PublicKeyToken=cc7b13ffcd2ddd51' 或其依赖项之一。这 定位的程序集的清单定义与程序集不匹配 参考。 (来自 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,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,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 并检查了清单,发现了以下内容
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。我错过了什么?
解决方法
重复绑定重定向被 clr 忽略。
这很尴尬。
我发现我对同一个 System.Threading.Tasks.Extensions
程序集有两个绑定重定向,系统正在使用找到的第一个并忽略第二个。没有人抱怨重复。
希望这个答案能在未来节省别人的时间。