Could not load file or assembly System.Web.Http, Version=5.2.2.0
Asked Answered
R

9

32

I've just uploaded a Asp.Net Web Api 2.2 project to production server and I got the error stated in the title.

In my Web.config I already have this:

 <dependentAssembly>
    <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-5.2.2.0" newVersion="5.2.2.0" />
  </dependentAssembly>

The file does exist in the bin. What would cause this?
All my Asp.Net Web API files are up to date and show 5.2.2 as the version. It works fine on my dev machine.

Rennin answered 2/12, 2014 at 13:23 Comment(1)
Before add webapi cors pls check we.http verion (****) use first neget package PM> Install-Package Microsoft.AspNet.WebApi.Cors add webcofiq - use old correct version <dependentAssembly> <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-(****)" newVersion="5.2.2.0" /> </dependentAssembly>Jobie
E
49

Set Copy Local to true in the properties for the System.Web.Http and System.Web.Http.WebHost assemblies and redeploy the package.

If this doesn't solve your problem completely try reinstalling the NuGet package. This will hopefully correct broken dependencies. From the package management console, run this command:

Update-Package Microsoft.AspNet.WebApi -reinstall

Make sure to install System.Web.Http.WebHost as well.

Eryneryngo answered 2/12, 2014 at 16:29 Comment(1)
reinstalling it did it for me.Aymara
R
12

For me, from "Solution Explorer" I checked the ver of "System.Web.Http" in the project references, which was 5.2.3.0 so, in the web.config, I changed:

<bindingRedirect oldVersion="0.0.0.0-5.2.2.0" newVersion="5.2.2.0" /> 

to

<bindingRedirect oldVersion="0.0.0.0-5.2.2.0" newVersion="5.2.3.0" />

then build. It worked for me!

Randell answered 12/9, 2015 at 16:27 Comment(3)
Look out all, this version has recently changed, so you'll need to go to 5.2.4.0 for your redirect. Otherwise this is the right answer (although I think you need to edit your old version to "0.0.0.0-5.2.3.0" in your second line.Staccato
Saved my day! Thanks.Condillac
This solved it for me. But there is no bindingRedirect yet. I added it and it solved it.Gotten
I
4

Adding below config inside web.cofig solved my issue.

  <dependentAssembly>
    <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.5.0" />
  </dependentAssembly>
Illuminant answered 9/5, 2018 at 8:9 Comment(0)
L
1

If you have an assembly in GAC with a different version, it will always be loaded, not the one from bin folder.

Latvian answered 2/12, 2014 at 14:11 Comment(2)
This is simply untrue. The dependentAssembly config he posted makes sure of that.Eryneryngo
That is what is not true. If you have an assembly in the GAC and another on the filesystem, same name and public key, try as you might, even loading its bytes, but you will always load the one from the GAC. Try it.Latvian
P
1

I solved the problem into the following steps:

  1. Stopping the site into the remote web server
  2. Cleaning the site folder
  3. Publishing it again
  4. Starting the site

One click publishing did not replace the correct version of dll or the remote site was keeping the file in use.

Phore answered 28/3, 2019 at 15:38 Comment(0)
B
1
  • Make sure you are referring the correct version of System.web.http in your project (check web.config).
  • If System.web.http is not present in reference, try to install it using nugets.
  • If both the above points are correct at your local then try to restore your nugets from package manager console
Boswell answered 12/12, 2019 at 7:16 Comment(0)
B
0

I ran into the same exact error. It was caused by a script I was using to deploy the application which replaced the Web.config with a previous version. The Web.config was specifying the wrong version of System.Web.Http. Removing that step solved the problem.

Baklava answered 11/5, 2016 at 13:42 Comment(0)
T
-1

Silly advise, but in my case restart Visual Studio helped me.

Talbert answered 24/11, 2021 at 13:23 Comment(0)
N
-4

Another way to do this, which do not require a New build or update/reinstall With Nuget is to do the following in config.web:

For the dll you have issues With, do the following:

&lt;bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="5.2.2.0"&gt;

I had an issue today, and this little tweak solved it...

Network answered 16/10, 2015 at 21:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.