Failed to load file or assembly System.Net.Http.Primitives. The located assembly manifest definition does not match the assembly reference

I am working on a program using the Google API. However, every time I run my program, I keep getting the following error:

Could not load file or assembly "System.Net.Http.Primitives, Version = 1.5.0.0, Culture = neutral, PublicKeyToken = b03f5f711d50a3a" or one of its dependencies. The located assembly manifest definition does not match the assembly reference.

I am using Visual Studio 2012 express. I tried this link and looked through many forums, but nobody is working. The main problem seems to come from the Google.Apis.dll DLL file that I referenced and refers to System.Net.Http.Primitives v1.5.0.0. However, the version of my soft links is 2.2.13.0. I tried to use the link to the program v1.5.0.0 (I managed to find the DLL along with the source code of Google.Apis), but this only caused another problem in which I needed a newer version of System.Net. Http. Primitives.

I am trying to find a way around this, but I cannot find anything that works. Thanks for the time.

+65
exception google-api-dotnet-client
Aug 22 '13 at 1:43 on
source share
15 answers

I ran into the same issue with the Google APIs. The main problem here is that if you install the Microsoft Http client libraries, it puts an updated version of the System.Net.Http.Primitives DLL into your project. Web.config assumes that you are still using the standard version 1.5. To fix this, two things must be done:

First: Upgrading to the latest versions of the Google APIs and Microsoft Http APIs. You can install updates through NuGet. Right-click on your website, click "Manage NuGet Packages", select "Updates on the Left." During this post, some of the Google APIs are only preliminary. You can install them through NuGet by selecting "enable pre-scan" in the upper left corner of the update screen.

Second Update / add dependent assembly to your web.config. To do this, you need to find out the version of installed System.Net.HTTP.Primitives.dll. Browse the bin directory in Windows Explorer. Locate System.Net.HTTP.Primitives.dll, right-click on it, select properties and select the Details tab. Pay attention to the version located there. At the time of this post, mine was 4.0.10.0.

Then add / update the dependAssembly section for the correct version.

<runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="System.Net.Http.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/> <bindingRedirect oldVersion="0.0.0.0-4.0.10.0" newVersion="4.0.10.0"/> </dependentAssembly> </assemblyBinding> </runtime> 
+69
Oct 18 '13 at 19:27
source

What worked for me was to simply install the Microsoft Http Client Libraries from Nuget.

+34
Oct 16 '13 at 19:14
source

Add the following text to your web.config (app.config):

 <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="System.Net.Http.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/> <bindingRedirect oldVersion="0.0.0.0-4.2.13.0" newVersion="4.2.13.0"/> </dependentAssembly> </assemblyBinding> </runtime> 
+5
Sep 09 '13 at 6:52
source

For me, it worked as follows:

In Visual Studio (2012)> Tools> Nuget Package Manager> Package Manager Console. At the top of the package manager console I have Package source: nuget.org Default project: a project that requires System.Net.Http.Primitives Watching inside the project file (yourproject.csproj) with an editor, I read which version is needed (in my case is Microsoft.Net.Http.2.2.28)

So, I went to https://www.nuget.org/packages/Microsoft.Net.Http/ , and I clicked on my version in the "Version History" section (scroll through the page a bit, see it). Selecting the version, you copy the proposed command - in my case it was:

Microsoft.Net.Http installation package -Version 2.2.28

but if you need the latest version, it is simple:

Microsoft.Net.Http installation package

and you paste it into the Visual Studio Package Manager console previously opened, as I described earlier. Run the command.

In the project, System.Net.Http.Primitives is updated by reference.

+3
Sep 24 '15 at 13:36
source

I had a similar problem.

Try updating nuget (tools / extensions and updates ...) Solved some other problems for me as well.

/ Jonas

+2
Aug 22 '13 at 13:57 on
source

We had a similar problem. But in my case, the decision to modify app.config from Paul did not work. The reason is that I use it as a plugin inside another application. Therefore, it examines the application configuration file. So we got the Google api code from GitHub and created the Google.Apis.Core library after removing the System.Net.Http.Primitives dependency. Then we used this DLL, which solved our problem.

+2
Jul 30 '15 at 13:24
source

The above build answer is correct, but you should NOT concern machine.config.

The subscription fee must be installed in the configuration file of all EXECUTABLE assemblies of your project (.exe.config) that reference your library, and not in library assemblies (.dll.config)

+1
May 30 '15 at 10:19
source

I ran into this problem when I released my code that uses Google.Apis.Drive.v2 (v1.9.2.1860) for the company I work for. I gave them exe and all the DLLs created by Visual Studio (and NuGet) and they got an error. I never got an error.

It was easy to fix (as soon as I understood): when installing api from Nuget, the file "assemblyname.exe.config" is automatically created in the output folder (aka, Debug or Release). All you have to do is include this file when you run the assembly somewhere other than the folder in which it was generated. Here is the code for this file for me:

 <?xml version="1.0" encoding="utf-8"?> <configuration> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> </startup> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="System.Net.Http.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-4.2.29.0" newVersion="4.2.29.0" /> </dependentAssembly> </assemblyBinding> </runtime> </configuration> 

This is basically a β€œsecond” fix, but it is automatically generated by the package manager. The problem for me was when I tried its β€œfirst” fix, updating it to Google.Apis.Auth and Google.Apis.Core (v1.9.3), which exacerbated the situation. I would get the same error, except that now there was an incorrect version for "Google.Apis.Core" (although it probably could also be resolved by including the same .exe.config file.)

Hope this helps someone, I know this thread is pretty old, but this is the one that Google quick search led me to.

Edit: forgot to mention, this applies to a console application designed for .NET 4.5. Some of them are probably still relevant for other .NET or ASP.NET purposes, but I don’t know for sure. Your mileage may vary.

+1
Sep 24 '15 at 15:25
source

Somehow the popular answer Paul Lemke didn't work for me. A project is a web form application that starts with .net v 2.0 and is upgraded to .net version 4.5

I updated the packages and nuget created the correct dependent_references / bindings of Redirects.

According to some comments, probably not the best idea is to modify the local machine.config file.

Apparently, I had an attribute in the web.config file that caused the application to ignore link binding.

 <configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"> 

I removed this xmlns attribute and started working.

0
Jul 20 '15 at 23:08
source

I managed to solve this quite easily. Just opened the Nuget package manager and updated the Microsoft ASP.NET Web API 2.2 client library package. This updated Microsoft.Net.Http for the latest version, which resolved the build issue of System.Net.Http.Primitives, to be able to be located. Hope this helps!

0
Aug 17 '15 at 20:34
source

In my case, I referenced the NuGet packages from the class library. NuGet does not tell us that the app.config class library is completely ignored, and we must manually copy its contents into the .exe app.config.

0
Oct 22 '15 at 18:43
source

NuGet has made the following change to Web.Config

<dependentAssembly> <assemblyIdentity name="System.Net.Http.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-4.2.22.0" newVersion="4.2.22.0" /> </dependentAssembly>

to

<dependentAssembly> <assemblyIdentity name="System.Net.Http.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-4.2.28.0" newVersion="4.2.28.0" /> </dependentAssembly>

This happened after installing and then uninstalling (using version control) this package https://www.nuget.org/packages/Microsoft.AspNet.WebApi.MessageHandlers.Compression/

0
Nov 25 '15 at 9:55
source

I had a similar problem with PowerShell scripts for TFS 2017. Scripts called .NET code to perform custom actions during build processes. I kept getting errors about dll version conflicts.

I was not able to solve the problem until I did bind to the AppDomain AssemblyResolve event according to this answer: Performing binding redirection for office add-ons

This solution forced the process to use the dll from the current path. I know this is a bit of a hack, but I read that when you start PowerShell, you cannot always use binding redirects, from which I could initially try: https://github.com/google/google-api-dotnet- client / issues / 555

0
Jun 16 '17 at 14:12
source

Microsoft.Net.Http installation package -Version 2.2.22

This version has this dll \ packages \ Microsoft.Net.Http.2.2.22 \ lib \ net45 \ System.Net.Http.Extensions.dll

0
Jan 09 '19 at 0:16
source

In my case, Nuget automatically adds the following to web.config

 <runtime xmlns=""> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-2.6.9.0" newVersion="2.6.9.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-2.6.9.0" newVersion="2.6.9.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-2.2.22.0" newVersion="2.2.22.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> </assemblyBinding> 

But I still got the error message above, finally understood. Copy these tags to the machine.config file located in the C: \ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ Config \ machine.config folder.

To find the "runtime" tag on machine.config, replace or add (if there is no such tag), these are your tags from your web.config (those listed above).

-2
Jun 26 '14 at 18:56
source



All Articles