【发布时间】:2016-02-16 11:58:12
【问题描述】:
我正在使用 .NET 框架 4.0 开发 C# 库。
在这个库上,我安装了这些 NuGet 包:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Bcl" version="1.1.10" targetFramework="net40" />
<package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net40" />
<package id="Microsoft.Bcl.Build" version="1.0.21" targetFramework="net40" />
<package id="Microsoft.Net.Http" version="2.2.29" targetFramework="net40" />
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net40" />
</packages>
这是我的 App.config 内容:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.2.29.0" newVersion="2.2.29.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.6.10.0" newVersion="2.6.10.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.6.10.0" newVersion="2.6.10.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
在这个项目中,我引用了System.Threading.Tasks version 2.6.10.0。我已经创建了一个安装程序并将这个项目安装在另一台计算机上。我在安装程序上添加了System.Threading.Tasks version 2.6.10.0(在 GAC 上安装这个 dll)。但是当我运行可执行文件时,我得到了这个错误:
Could not load file or assembly 'System.Threading.Tasks, Version=1.5.11.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
at MyProject.Common.WebApi.Client.AsyncHelpers.<>c__DisplayClass7 1.<RunSync>b__6(Object _)
at MyProject.Common.WebApi.Client.AsyncHelpers.ExclusiveSynchronizationContext.BeginMessageLoop()
at MyProject.Common.WebApi.Client.AsyncHelpers.RunSync[T](Func 1 task)
at MyProjectCodesManagerWindowsService.WebApi.Client.MyProjectCodesManagerClient.PrepareAndStartv2(String orderNumber, String userName, String systemName)
但在我引用的所有项目中,System.Threading.Tasks version 2.6.10.0。
为什么我会收到此异常?有什么建议吗?
我已检查此页面https://blogs.msdn.microsoft.com/bclteam/p/asynctargetingpackkb/ 中的所有问题,但结果相同。
在这个页面之后,http://pauliom.com/2012/01/30/how-to-log-net-binding-errors-when-you-dont-have-fuslogvw-exe/,我得到了这个日志:
Calling assembly : Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.
===
LOG: Start binding of native image System.Threading.Tasks, Version=1.5.11.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.
WRN: No matching native image found.
问题在于Microsoft.Threading.Tasks, Version=1.0.12.0,它是 System.Threading.Tasks 版本=1.5.11.0 的依赖项。我在文件夹 D:\packages\Microsoft.Bcl.1.1.10\lib\sl4\ 上找到了那个 dll。
使用程序 .NET Reflector 我已经看到 Microsoft.Threading.Tasks, Version=1.0.12.0 与 System.Threading.Tasks version=1.5.11.0 有依赖关系。
当我修改所有 App.config 文件以使用版本 2.6.10.0 时,为什么它使用该 dll 版本?
【问题讨论】:
-
你已经知道 Fuslogvw.exe 的作用了,为什么不使用它??
-
我在没有 Visual Studio 的机器上运行,问题出在带有 Windows 窗体用户控件的项目上。顺便说一句,我不知道如何使用 Fuslogvw.exe。在我的开发机器上我没有这些问题。
-
你可能犯的唯一错误就是不尝试。
-
我已经用很多细节更新了我的问题。
标签: c# .net visual-studio base-class-library