Could not load file or assembly System.Net.Http.Primitives. Located assembly's manifest definition does not match the assembly reference
Asked Answered
H

15

68

I'm working on a program that uses the Google API. However every time I run my program, it I keeps 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's manifest definition does not match the assembly reference.

I'm using Visual Studio 2012 express. I've tried following this link and looked through many forums, but none seem to work. The main problem seems to come from the DLL file "Google.Apis.dll" which I referenced, and it references System.Net.Http.Primitives v1.5.0.0. However the version my program references is 2.2.13.0. I've tried having the program reference v1.5.0.0 instead (I manage to find the dll along with the source code of Google.Apis) however this only caused another problem in which I needed a more recent version of System.Net.Http.Primitives.

I'm been trying find a way to work around this, however I can't seem to find anything that works. Thank you for time.

Harriot answered 22/8, 2013 at 1:43 Comment(4)
https://mcmap.net/q/282241/-why-do-i-sometimes-get-quot-could-not-load-file-or-assembly-ajaxcontroltoolkit-version-3-0-quot/62576Brochu
Hello! Where you able to solve this issue? I have the same problem. Thank you!Faradize
I got the same error message for a Web API project though I was not using Google API. Rebuilding the project solved the problem.Brainbrainard
Another clear case of nuget dll hellPozzuoli
P
71

I ran into the same issue with the Google API's. The main issue here is if you install the Microsoft Http Client Libraries it puts in your project an updated version of the System.Net.Http.Primitives DLL. The web.config assumes you are still using the default version of 1.5. There are two things that need to happen to fix it:

First: Update to the latest versions of Google API and Microsoft Http Client Libraries. You can install the updates via NuGet. Right click on your website, click "Manage NuGet Packages", select Updates on the left. At the time of this post some of the Google API's are prerelease only. You can install them via NuGet by selecting "include prerelease" on the top left of the update screen.

Second Update/add a dependentAssembly into your web.config. To do this you need to know the version of the System.Net.HTTP.Primitives.dll that was installed. Look in your bin directory within Windows Explorer. Find System.Net.HTTP.Primitives.dll, right click on it, select properties, and click the "Details" tab. Note the version located there. At the time of this post mine was 4.0.10.0.

Then add/update a dependentAssembly 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>
Proxy answered 18/10, 2013 at 19:27 Comment(5)
+1 First step was enough to resolve the issue for meExplicate
Just to point out Http.Primitives version is "2.2.22.0" and the example code shows "4.0.10.0". But this is the right answer, should be acceptedPiddling
The point of Nuget is to not require manual assembly binding in the Web.Config. I miss the old Google API already. Now If I distribute my wrapper DLL, I have to somehow notify them to do your two steps for any project that wants to use it.Quartermaster
Thanks! This fixed an error "Method 'MyMethod' in type 'MyClass' from assembly 'MyAssembly' does not have an implementation." that only appeared when inheriting from a type in Google.Apis.Auth.Mvc4.dll. All I had to do was copy the bindingRedirect already in my app.config to my nunit config file.Madame
Update with Nuget (first step) also solved the problem for me.Rigel
F
34

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

Flaccid answered 16/10, 2013 at 19:14 Comment(5)
What namespaces did you use after installing? ThxFaradize
This worked for me when I added it specifically to my test project (where I was running in to the issue), regardless of the fact that it was already referenced in the main project which was in turn referenced by my test project.Hebetic
And to do this, i had to update nuget.exe in our solution - seirer.net/blog/2014/5/20/…Desensitize
Install-Package Microsoft.Net.HttpKofu
Niether Microsoft.Net.Http nor System.Net.Http nuget packages include the System.Net.Http.Primitives.dll. Not sure if they did in the past. My search continues.Pam
M
5

Add following 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>
Messidor answered 9/9, 2013 at 6:52 Comment(3)
Not sure about your oldVersion range value and newVersion value, my newVersion value is: 2.2.29.0Permission
4.2.29 for me, targeting .Net 4.5Vindictive
In my case the vesrion nuget created was pointing to 4.2.29 but the version I had on my machine was actually 4.2.13 (GAC_MSIL\System.Net.Http.Primitives) ... when I changed the redirect to 4.2.13, it started working! Not sure why it happened but if anyone trying all kinds of workaround and still not able to make it work, it's worth a check at your GAC and see what version you actually have.Cortisol
R
5

For me it worked the following:

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

So I went to https://www.nuget.org/packages/Microsoft.Net.Http/ and I clicked on my version under "Version History" (scroll a bit the page if you don't see it). After choosing the version you copy the suggested command - in my case it was:

Install-Package Microsoft.Net.Http -Version 2.2.28

but if you need the latest version is just this:

Install-Package Microsoft.Net.Http

and you paste it on your Visual Studio Package Manager Console previously opened as I described before. Execute the command.

In the project under the references, System.Net.Http.Primitives is now updated.

Reggy answered 24/9, 2015 at 13:36 Comment(0)
C
2

I've had a similar problem.

Try to update nuget (tools/extensions and updates...) Solved that and some other problems for me.

/Jonas

Cellulous answered 22/8, 2013 at 13:57 Comment(0)
O
2

We were having the similar problem. But in my case, the solution of modifying the app.config by Paul didn't work. The reason is I am using it as a plugin inside another application. So it considers that application's configuration file. So we got the Google api code from GitHub and built the Google.Apis.Core library after removing the dependency of System.Net.Http.Primitives. Then we used that dll which solved our issue.

Oribel answered 30/7, 2015 at 13:24 Comment(0)
A
2

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

The fix was easy (once I figured it out): When installing the api from Nuget the file 'assemblyname.exe.config' is automatically generated in the output (aka, Debug or Release) folder. All you have to do is include that file when you are running the assembly somewhere other than the folder it was generated. Here's the code for that 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 Paul's "second" fix but it's automatically generated by the package manager. The issue for me was when I tried his "first" fix by updating to Google.Apis.Auth and Google.Apis.Core (v1.9.3) it made things worse. I'd get the same error except now it was for "Google.Apis.Core" was the wrong version (although that probably could have been solved as well by including the same .exe.config file.)

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

Edit: Forgot to mention, this is relevant to a console application targeting .NET 4.5. Some of it is probably still relevant to other .NET targets or ASP.NET but I don't know for sure. Your mileage may vary.

Accused answered 24/9, 2015 at 15:25 Comment(1)
Sorry to bump this, but this actually was the only fix for me. It explains why it would run within the debug map/debug mode and not in the released folder. Is there any way to prevent this though? Alot of info is shown there for easy grabs, wich normal users aren't suppose to access easily.Derte
K
1

The above answer about assemblybinding are correct, but you should NOT touch the machine.config.

The assemblybinding must be set in the config file of all of the EXECUTABLE assemblies of your project (.exe.config) who reference your library, and not in the library assemblies (.dll.config)

Kobe answered 30/5, 2015 at 10:19 Comment(0)
C
1

NuGet made the following change in 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 was following install and subsequent removal (by version control revert) of this package https://www.nuget.org/packages/Microsoft.AspNet.WebApi.MessageHandlers.Compression/

Corsair answered 25/11, 2015 at 9:55 Comment(0)
N
0

Somehow the popular answer by Paul Lemke was not working for me. The project is a webforms application that started with .net v 2.0 and has been upgraded to .net version 4.5

I updated the packages and nuget created the correct dependentAssembly/bindingRedirects.

As per some of the comments, it probably is not the best idea to change your local machine.config file.

Apprently I had an attribute in my web.config file that was causing the app to ignore the bindingRedirects.

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

I removed that xmlns attribute and it started working.

Nous answered 20/7, 2015 at 23:8 Comment(0)
A
0

Was able to resolve this pretty easily. Just opened up the Nuget Package Manager and updated the Microsoft ASP.NET Web API 2.2 Client Library package. This updated Microsoft.Net.Http to the newest version which resolved the issue with the System.Net.Http.Primitives Assembly from being able to be located. Hope this helps!

Aargau answered 17/8, 2015 at 20:34 Comment(0)
C
0

In my case I was referencing the NuGet packages from a class library. NuGet fails to inform us that the class library's app.config is completely ignored and we have to manually copy its contents to the .exe's app.config.

Cottonmouth answered 22/10, 2015 at 18:43 Comment(2)
Where do you find the library’s app.config? Did you copy all its contents?Liaison
It is normally in the root of the project folder and is copied to bin\Foo.dll.config during compile. They are XML format so one usually can't just copy append it verbatim. They need to be compared and the missing parts individually copied.Cottonmouth
P
0

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

I was unable to resolve the issue until I implemented a hook into the AppDomain AssemblyResolve event as per this answer: Making binding redirects work for office add-ins

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

Portauprince answered 16/6, 2017 at 14:12 Comment(0)
N
0

Install-Package Microsoft.Net.Http -Version 2.2.22

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

Nitroparaffin answered 9/1, 2019 at 0:16 Comment(0)
L
-2

In my case, Nuget automatic add 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 above error Message, finally I figure it out. You have to copy those tags to the machine.config file located at C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\machine.config.

To find the tag of "runtime" on machine.config, replace or add(if there is no such tag) it with your tags from your web.config (the ones I listed just above).

Log answered 26/6, 2014 at 18:56 Comment(1)
@flyhorse1999, about a year late but try the solution I posted. My application did not listen to the bindingRedirects due to an attribute I needed to remove.Nous

© 2022 - 2024 — McMap. All rights reserved.