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

3

17

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>
Lucerne answered 19/1, 2014 at 8:40 Comment(2)
I am having an identical issue. Were you able to resolve your issue, and if so, how?Niche
i solve it by updating google libraries to the recent ones and installing .net 4.5, it was always working on my development machines as it has .net 4.5, I install it on clients computer and remove the erroneous dependency assembly from app.configLucerne
E
14

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.

Erethism answered 19/1, 2014 at 9:33 Comment(5)
i followed the instructions after removing the highlighted assemblies now i get Could not load file or assembly System.Threading.Tasks, Version=1.5.11.0Lucerne
Check issue 9 of the same article.Erethism
How would I accomplish the "Add as Link" in the solution for issue 9 if I am using the installer project instead of ClickOnce? I am targeting .net 4.0 if that is relevant.Windle
@Carl The discussion was carried out in 2014. After that Microsoft did make improvements in newer .NET Framework releases to address such issues like written in the release notesErethism
Sure, but I haven't found a good way to determine which of the 100 packages in use has a dependency on the task package. I don't have time to upgrade and test each one. For anyone else in my position - getting rid of the assembly binding for System.Runtime made the differenceCardiomegaly
P
1

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

Programme answered 25/10, 2016 at 19:15 Comment(0)
S
0

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.

Smolder answered 30/10, 2018 at 13:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.