Could not load file or assembly 'System.Web.Http 4.0.0 after update from 2012 to 2013

I fixed this by reinstalling the NuGet package, which corrects broken dependencies. From the package manager, run:

Update-Package Microsoft.AspNet.WebApi -reinstall

To resolve the Could not load file or assembly 'System.Web.Http' error use NuGet to install the Web API 2.1 WebHost.

In solution explorer in the references right click and select manage nuget packages. (if not there install nuget)

enter image description here

In the manage NuGet Packages window on the left side click online then in top right search for Web Host and install Microsoft ASP.NET Web API 2.1 Web Host. (Once installed the install button will change to a green check)

After that the project will reload and when it's build again the error will be resolved and the project will debug and run. The error will be gone and you may be 'The resource cannot be found. Just append the url ( ex from localhost:52088/ to localhost:52088api/products )

Your question was good and helped me.

Hope this answer helps!


You need to add assembly redirects:

<configuration>

   ....

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

   ...

</configuration>

Most likely you have to do this for a few more assemblies like webhosting, etc.


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


When I installed Web Api 2.2 help this error started. I added this to the web.config and it solved my problem.

  <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>