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

前端 未结 28 1099
悲哀的现实
悲哀的现实 2020-11-28 01:09

I did the upgrade according to. http://www.asp.net/mvc/tutorials/mvc-5/how-to-upgrade-an-aspnet-mvc-4-and-web-api-project-to-aspnet-mvc-5-and-web-api-2

I get the er

相关标签:
28条回答
  • 2020-11-28 01:37

    Just an obvious but possible helpful hint....remember to check that the new version you specify in your webconfig assembly binding is the same version that you reference in your project references. (ie as I write this...this would be 5.1.0.0 if you have recently done a NUGet on System.Web.Http

    0 讨论(0)
  • 2020-11-28 01:38

    What solved the problem for me was re-installing the Microsoft ASP.NET Web API 2.2 Help Page and Microsoft ASP.NET Web API 2.2 OWIN packages. I re-installed both at the same time, but I think it was the former that fixed the issue.

    I tried the first few of the solutions offered here but that didn't help, then I compared my dependencies with the ones in a project that worked (from a course on Pluralsight) and the two dependencies above were a lower version (5.0.0) so I updated them to 5.2.3 and it started working.

    0 讨论(0)
  • 2020-11-28 01:38

    ASP.NET Version:4.0.30319.18408 belongs to .Net4.5 and System.Web.Http Version=4.0.0.0 is compatible for .NET4.0. So the versions that you have are not compatible. You should update you System.Web.Http to version 5.0.0.0, which is compatible with .Net4.5

    0 讨论(0)
  • 2020-11-28 01:38

    I had the same problem with System.Web.Http.WebHost, Version=5.2.6.0 being referenced but the latest NuGet package was 5.2.7.0. I edited the web.config files, re-installed the NuGet package, then edited the visual studio project files for all of my projects to make sure no references to 5.2.6.0 persisted. Even after all this, the problem persisted.

    Then I looked in the bin folder for the project that was throwing the exception, where I found a DLL for one of my other projects that is not a dependency and should never have been there. I deleted the offending DLL (which had been compiled using the 5.2.6.0 version of System.Web.Http.WebHost), rebuilt the troublesome project, and now it is working.

    0 讨论(0)
  • 2020-11-28 01:40

    I had a similar issue. Everything was working before. It's was originally made using Web Forms and later on added Web API for some things.

    • Tried uninstalling, installing and reinstalling Microsoft.AspNet.WebApi package.
    • Tried removing packages folder from solution and letting NuGet restore in VS.
    • Tried removing individual assembly references (under References) and reinstalling packages.
    • Tried adding binding redirects to 5.2.3.0 version in web.config mentioned in several answers. Nothing worked for me.

    What worked was, in Visual Studio, change publish profile settings from Release to Debug. Strange, but that's what worked. So sharing here.

    0 讨论(0)
  • 2020-11-28 01:41

    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.

    0 讨论(0)
提交回复
热议问题