我有以下代码
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 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.
我打开了bin
在 IL Disassembler 中找到的 DLL 并检查了清单,发现以下内容
System.Threading.Tasks.Extensions.DLL 是 4.2.0.1 以上依赖于已经在 bin 中的 System.Runtime.CompilerServices.Unsafe 4.0.4.1。
所以 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>
我仍然收到相同的运行时错误抱怨,它没有找到扩展 4.2.0.0。我错过了什么?