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

我只是一个虾纸丫 提交于 2019-12-03 14:56:41

问题


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.


回答1:


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.




回答2:


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!




回答3:


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>



回答4:


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




回答5:


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.




回答6:


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.




回答7:


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



来源:https://stackoverflow.com/questions/27250581/could-not-load-file-or-assembly-system-web-http-version-5-2-2-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!