Could not load file or assembly System.Threading.Tasks, Version=2.5.19.0

别等时光非礼了梦想. 提交于 2019-11-30 12:12:29

You might start from Microsoft BCL team blog and clean up the app.config by removing the wrong entries,

http://blogs.msdn.com/b/bclteam/p/asynctargetingpackkb.aspx

Issue 6

Symptoms

When adding the NuGet package to a project that is consumed by another project with a different target framework you might see warnings similar to the following:

The primary reference "Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" could not be resolved because it has an indirect dependency on the framework assembly "System.Runtime, Version=2.5.19.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.5". To resolve this problem, either remove the reference "Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" or retarget your application to a framework version which contains "System.Runtime, Version=2.5.19.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".

The primary reference "Microsoft.Threading.Tasks.Extensions, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" could not be resolved because it has an indirect dependency on the framework assembly "System.Runtime, Version=2.5.19.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.5". To resolve this problem, either remove the reference "Microsoft.Threading.Tasks.Extensions, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" or retarget your application to a framework version which contains "System.Runtime, Version=2.5.19.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".

Solution

The problem is that NuGet added incorrect binding redirects for platform assemblies. To remove them, please open the app.config for the project that caused the warnings and remove the highlighted entries (StackOverflow does not support highlight):

 <?xmlversion="1.0"encoding="utf-8"?>
   <configuration>   
    <runtime>
     <assemblyBindingxmlns="urn:schemas-microsoft-com:asm.v1">
       <dependentAssembly>                     
         <assemblyIdentityname="System.Runtime"publicKeyToken="b03f5f7f11d50a3a"culture="neutral" />
         <bindingRedirectoldVersion="0.0.0.0-2.5.19.0" newVersion="2.5.19.0" />
       </dependentAssembly>
       <dependentAssembly>
         <assemblyIdentityname="System.Threading.Tasks"publicKeyToken="b03f5f7f11d50a3a"culture="neutral" />
         <bindingRedirectoldVersion="0.0.0.0-2.5.19.0" newVersion="2.5.19.0" />
       </dependentAssembly>
      </assemblyBinding>
    </runtime>
  </configuration>

Update by Lex Li:

With .NET Framework 4.0 end-of-life, you should think twice before using the async targeting pack yourself. If this dependency comes from a NuGet package, you should also check whether the NuGet package has a newer version that has no such dependency.

I had a very similar issue ("Could not load file or assembly Microsoft.Threading.Tasks, Version=1.0.12.0") in a UWP project (VS2015) and I solved it by installing the Microsoft.Bcl.Async package from NuGet

I had the exact same problem but it was caused by the assembly Microsoft.Rest.ClientRuntime. In my case all I had to do was to set "Copy local=True" on the reference to Microsoft.Rest.ClientRuntime.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!