Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 274
Tri Avatar asked Aug 22 '13 01:08

Tri


People also ask

Can not load file or assembly or one of its dependencies?

In summary if you get the "Could not load file or assembly error", this means that either your projects or their references were built with a reference to a specific version of an assembly which is missing from your bin directory or GAC.

Could not load file or assembly system Cannot find file specified?

For the alert error ("The system cannot find the file specified.") Right click on [Solution Program name] then select Build Dependencies> & left click on Build Customizations... then true-checkbox {MASM} then click OK button.

Could not load file or assembly or one of its dependencies the module was expected?

Look at your project's bin folder and see if your project's dll has a conflict in it's name. Just delete that one and then Rebuild your solution. That worked for me.


2 Answers

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> 
like image 181
Paul Lemke Avatar answered Sep 23 '22 06:09

Paul Lemke


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

like image 35
Senkwe Avatar answered Sep 19 '22 06:09

Senkwe