Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have a WPF (.NET 4) project using google url shortener API, I have installed the client library through nugget https://www.nuget.org/packages/Google.Apis.Urlshortener.v1/1.7.0.25-beta

the application works fine in visual studio but once published it throws the exception Could not load file or assembly System.Threading.Tasks, Version=2.5.19.0 this and all other assemblies are present in the installation folder, and it gets publish with application. I have searched internet and people suggest to manually bind the dependency libraries in the app.config, it still does not work as all of my dependency libraries are already mentioned in app.config, below is how my app.config looks like

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-2.5.19.0" newVersion="2.5.19.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-2.5.19.0" newVersion="2.5.19.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.1.10.0" newVersion="2.1.10.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Net.Http.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-2.1.10.0" newVersion="2.1.10.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="log4net" publicKeyToken="669e0ddf0bb1aa2a" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-1.2.13.0" newVersion="1.2.13.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Threading.Tasks.Extensions.Desktop" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-1.0.165.0" newVersion="1.0.165.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
like image 358
Syed Waqas Avatar asked Jan 19 '14 08:01

Syed Waqas


2 Answers

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 (archive)

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 [noted by *****]:

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

Commentary:

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.

like image 101
Lex Li Avatar answered Oct 05 '22 22:10

Lex Li


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

like image 30
Detail Avatar answered Oct 06 '22 00:10

Detail