Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 365
Mike_G Avatar asked Dec 02 '14 13:12

Mike_G


3 Answers

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.

like image 79
Mihai Dinculescu Avatar answered Nov 17 '22 09:11

Mihai Dinculescu


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!

like image 12
Daniel B Avatar answered Nov 17 '22 09:11

Daniel B


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>
like image 3
M.Laida Avatar answered Nov 17 '22 09:11

M.Laida