Failed to load file or assembly System.Threading.Tasks, Version = 2.5.19.0

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

the application works fine in the visual studio, but after publishing it throws an exception Failed to load the file or assembly System.Threading.Tasks, Version = 2.5.19.0 this and all other assemblies are present in the installation folder, and it is published with the application. I searched the Internet and people suggest manually linking the dependency libraries in app.config, it still does not work, since all my dependency libraries are already mentioned in app.config, below is what 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> 
+7
c # wpf google-api url-shortener
source share
2 answers

You can start with the Microsoft BCL team blog and clear app.config by deleting the wrong entries,

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

Problem 6

Symptoms

When you add a NuGet package to a project that is consumed by another project with a different target structure, you can see warnings similar to the following:

The main link "Microsoft.Threading.Tasks, Version = 1.0.12.0, Culture = Neutral, PublicKeyToken = b03f5f7f11d50a3a, processorArchitecture = MSIL" cannot be resolved because it has an indirect dependency on the system build "System.Runtime, Version = 2.5.19.0 , Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a "which cannot be resolved within the target framework. ".NETFramework, Version = v4.5." To fix this problem, delete the link "Microsoft.Threading.Tasks, Version = 1.0.12.0, Culture = Neutral, PublicKeyToken = b03f5f7f11d50a3a, processorArchitecture = MSIL" or reconfigure the application to which it contains "System.Runtime, Version = 2.5.19.0, Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a ".

The main link "Microsoft.Threading.Tasks.Extensions, Version = 1.0.12.0, Culture = Neutral, PublicKeyToken = b03f5f7f11d50a3a, processorArchitecture = MSIL" cannot be resolved because it has an indirect dependency on the system assembly "System.Runtime, Version = 2.5 .19.0, Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a "which cannot be resolved within the target framework. ".NETFramework, Version = v4.5." To fix this problem, delete the link "Microsoft.Threading.Tasks.Extensions, Version = 1.0.12.0, Culture = Neutral, PublicKeyToken = b03f5f7f11d50a3a, processorArchitecture = MSIL" or reconfigure the application to which contains "System.Runtime, Version = 2.5.19.0 , Culture = Neutral, PublicKeyToken = b03f5f7f11d50a3a ".

Decision

The problem is that NuGet has added invalid binding redirects for platform builds. To remove them, open app.config for a project that triggered warnings and deleted highlighted entries ( StackOverflow does not support highlighting ):

  <?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 from Lex Lee:

With the end of life of the .NET Framework 4.0, you should think twice before using asynchronous targeting. If this dependency comes from the NuGet package, you should also check if the NuGet package has a newer version that does not have such a dependency.

+9
source share

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

0
source share

All Articles