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

C# RabbitMQ连接工厂在我的应用程序bin中找不到System.Threading.Tasks.Extensions,c#,rabbitmq,assembly-binding-redirect,.net-framework-4.8,assemblybinding,C#,Rabbitmq,Assembly Binding Redirect,.net Framework 4.8,Assemblybinding,我有以下代码 var factory = new ConnectionFactory() { HostName = "path.to.host.net", UserName = "guest", Password = "guest", VirtualHost = "myhost" }; var connection = factory.CreateConnection(); 上面的最

我有以下代码

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=CC7B13FFCD2DD51'或其依赖项之一。这个 定位程序集的清单定义与程序集不匹配 参考资料。(来自HRESULT的异常:0x8013100)

我检查了融合日志,上面写着

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,并检查了清单,发现了以下内容

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.
System.Threading.Tasks.Extensions.DLL为4.2.0.1 以上内容取决于bin中已经存在的System.Runtime.CompilerServices.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。我缺少什么?

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

这很尴尬

我发现对于同一个
System.Threading.Tasks.Extensions
assembly,我有两个绑定重定向,系统使用找到的第一个,忽略了第二个。而且也没有人抱怨复制品


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

伙计,你已经花了好几个小时了。我的配置中没有重复项,但试图找出System.Threading.Channels调用.0版本的原因,而我们在构建目录中得到的是.1。超级讨厌。绑定重定向是可插拔基础架构中的一个难题。这确实让我想到了下一个问题。谢谢@TravisWhidden您可以发布一个答案,包括您案例中的不同之处吗?