Microsoft.Threading.Tasks引用了不正确的System.Threading.Tasks.dll版本 [英] Microsoft.Threading.Tasks referencing an incorrect System.Threading.Tasks.dll version

查看:188
本文介绍了Microsoft.Threading.Tasks引用了不正确的System.Threading.Tasks.dll版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用.NET Framework 4.0开发C#库.

I'm developing a C# library with .NET framework 4.0.

在此库上,我安装了以下NuGet软件包:

On this library I have these NuGet packages installed:

<?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内容:

This is my App.config content:

<?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).但是当我运行可执行文件时,出现此错误:

On this project I'm referencing System.Threading.Tasks version 2.6.10.0. I have created an installer and install this project in another computer. I have added System.Threading.Tasks version 2.6.10.0 on the installer (that install this dll on GAC). But when I run the executable I get this error:

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.

But on all of the projects I'm referencing System.Threading.Tasks version 2.6.10.0.

为什么我会收到此异常?有什么建议吗?

Why I'm getting this exception? Any advice?

我已经检查了此页面 https://blogs.msdn中的所有问题. microsoft.com/bclteam/p/asynctargetingpackkb/,但结果相同.

I have checked all the issues from this page https://blogs.msdn.microsoft.com/bclteam/p/asynctargetingpackkb/ but with the same result.

在此页面之后,

Following this page, http://pauliom.com/2012/01/30/how-to-log-net-binding-errors-when-you-dont-have-fuslogvw-exe/, I got this log:

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.

The problem is with Microsoft.Threading.Tasks, Version=1.0.12.0 it is a dependency with System.Threading.Tasks version=1.5.11.0. I have found that dll on folder D:\packages\Microsoft.Bcl.1.1.10\lib\sl4\.

使用程序.NET Reflector我已经看到Microsoft.Threading.Tasks, Version=1.0.12.0System.Threading.Tasks version=1.5.11.0有依赖关系.

Using program .NET Reflector I have seen that Microsoft.Threading.Tasks, Version=1.0.12.0 has a dependency with System.Threading.Tasks version=1.5.11.0.

当我将所有App.config文件修改为使用2.6.10.0版本时,为什么使用该dll版本?

Why is it using that dll version when I have modified all App.config files to use version 2.6.10.0?

推荐答案

我找到了解决方案.

我必须添加这个:

<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>

进入程序的App.Config,它将使用我的库.

into the program's App.Config that it is going to use my library.

问题是我必须将我的库中的dependentAssembly添加到要使用该库的程序的app.config中.

The problem was that I have to add dependentAssembly from my library into the program's app.config that it's going to use this library.

我在这里找到了解决方案:

I have found the solution here: https://social.msdn.microsoft.com/Forums/en-US/f0653a7f-4196-4b5e-8d96-61d75fb8274e/gac-dll-and-appconfig?forum=clr

这篇关于Microsoft.Threading.Tasks引用了不正确的System.Threading.Tasks.dll版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆