如何在.Net 4.0中使用和部署Microsoft.Bcl.Async?

时间:2015-02-17 09:54:34

标签: .net async-await base-class-library

我们有以下环境:

1)第三方桌面应用程序App.exe针对.Net 4.0。

2)我们的plugin.dll以.Net 4.0为目标,由App.exe动态加载。

3)我们的插件使用Microsoft.Bcl.Async。

4)随着我们的插件,我们分发:

  • Microsoft.Threadng.Tasks.dll
  • Microsoft.Threadng.Tasks.Extensions.dll
  • Microsoft.Threadng.Tasks.Extensions.Desktop.dll
  • System.Threading.Tasks.dll
  • System.IO.dll
  • System.Runtime.dll

所以,最后我们在客户端系统上有以下目录结构:

App /
    App.exe
    App.config
    plugin.dll
    Microsoft.Threadng.Tasks.dll
    Microsoft.Threadng.Tasks.Extensions.dll
    Microsoft.Threadng.Tasks.Extensions.Desktop.dll
    System.Threading.Tasks.dll
    System.IO.dll
    System.Runtime.dll

我们的问题是,如果客户端系统安装了.Net 4.5,一切正常,但如果客户端系统有.Net 4.0,则App.exe无法加载我们的插件:

System.IO.FileLoadException 无法加载文件或程序集“System.Threading.Tasks,Version = 1.5.11.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'或其中一个依赖项。定位的程序集清单定义与程序集引用不匹配。

如果我们修改App.config以从我们的发行版重定向绑定到System.Threading.Tasks,那么错误就会消失。但我认为这不是一个好的解决方案。

我强烈认为我们做错了什么,但我没有足够的.Net经验来正确解决这个问题。

另外,我的猜测是正确的,Bcl.Async允许代码定位到.Net 4.0使用async / await而不需要重新定位到.Net 4.5吗?

任何人都可以帮助我吗?

UPDATE Fuslogvw输出:

*** Assembly Binder Log Entry  (2/17/2015 @ 5:28:39 PM) ***

The operation failed.
Bind result: hr = 0x80131040. No description available.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  C:\Program Files (x86)\Third-party App\bin\ThirdParty.App.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: User = Administrator
LOG: DisplayName = System.Threading.Tasks, Version=1.5.11.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
 (Fully-specified)
LOG: Appbase = file:///C:/Program Files (x86)/Third-party App/bin/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = ThirdParty.App.exe
Calling assembly : Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Program Files (x86)\Third-party App\bin\ThirdParty.App.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: System.Threading.Tasks, Version=1.5.11.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Third-party App/bin/System.Threading.Tasks.DLL.
LOG: Assembly download was successful. Attempting setup of file: C:\Program Files (x86)\Third-party App\bin\System.Threading.Tasks.dll
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: System.Threading.Tasks, Version=2.6.8.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
WRN: Comparing the assembly name resulted in the mismatch: Major Version
ERR: The assembly reference did not match the assembly definition found.
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

0 个答案:

没有答案