asp.net-mvc-4 c# globalconfiguration - Could not load file or assembly System.Net.Http, Version=22.214.171.124 with ASP.NET (MVC 4) Web API OData Prerelease
Visual Studio 2013 has a new feature to take care of this. When you build the app, you should see warnings about different versions of an assembly being referenced. Double click the warning to add assembly binding redirects to the web.config.
See http://msdn.microsoft.com/en-us/library/2fc472t2.aspx for more details.
jeff.eynon notes below that you need to have the web.config checked out (if using TFS source control) to get VS to edit the file automatically. Thanks for the tip!
After installing the Microsoft ASP.NET Web API OData package 5.0.0-rc1 prerelease I end up with the following exception:
Could not load file or assembly 'System.Web.Http, Version=126.96.36.199, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
My MVC 4 project is brand new and really small, nothing fancy in it. I target .NET framework 4.5
How can I fix that?
My versions of System.Web.Http
In GAC I have version 188.8.131.52 of System.Web.Http
gacutil -l System.Web.Http The Global Assembly Cache contains the following assemblies: System.Web.Http, Version=184.108.40.206, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL
In Visual Studio, when I browse assemblies, the given version of System.Web.Http is 220.127.116.11 (Why?)
In my project, the reference to System.Web.Http
- Has the version 18.104.22.168
- Points to the \lib\net45\ folder of the package
- Has CopyLocal=true
Things I tried
I tried to bind redirect v 22.214.171.124 to 126.96.36.199 in Web.config
<dependentAssembly> <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" /> <bindingRedirect oldVersion="188.8.131.52-184.108.40.206" newVersion="220.127.116.11" /> </dependentAssembly>
But it gives me another exception:
Attempt by method 'System.Web.Http.GlobalConfiguration..cctor()' to access field 'System.Web.Http.GlobalConfiguration.CS$<>9__CachedAnonymousMethodDelegate2' failed.
I guess that v 18.104.22.168 really need to be used by core Web Api engine.
I met the same problem and I resolved it by setting CopyLocal to true for the following libs:
I must to add that I use MVC4 and NET 4
Or you could do this from NuGet Package Manager Console
Install-Package Microsoft.AspNet.WebApi -Version 5.0.0
And then you will be able to add the reference to System.Web.Http.WebHost 5.0
This error popped up several times on several different projects.
What I finally figured out is that when I would build, there was already a copy of the system.web.mvc binary assembly in my bin folder.
To fix this, right-click on the assembly in the list of references and select "properties". Check to see if this is the latest version by looking at the "Version" property. If it is, switch "Copy Local" to true.
This will make sure that the version referenced in your project is the version that will end up in your binaries folder.
If you still get the error, try running nuGet to get the latest version, then try the aforementioned again.
Good luck - this error is a pain!
i solve by way nuget. the first you install nuget.
the second you use.
third : Check to see if this is the latest version by looking at the "Version" property.
The finaly : you check project have latest version again.
After modifying the References in the
Web.config file as mentioned above, we resolved the references.
I was facing similar issue.
For us we have reference
OData.dll and other assemblies from Program Files:
C:\Program Files (x86)\Microsoft WCF Data Services\5.0 \bin\.NETFramework\Microsoft.Data.Edm.dll
C:\Program Files (x86)\Microsoft WCF Data Services\5.0 \bin\.NETFramework\Microsoft.Data.OData.dll
and version was 5.6.4.
Once I change the reference of both assemblies to
C:\....Project\packages\Microsoft.Data.Edm.5.6.0 , the issue was resolved
If this issue occurs, kindly check web.config in below section
after checking this section in web.config, open solution explorer and select reference from the project tree as shown . Solution Explorer->Reference
After expanding reference, find the dll which caused the error. Right click on the dll reference and check for version like shown in the image above.
If both config dll version and referenced dll is different you would get this exception. Make sure both are of same version which would help.