Could not load file or assembly System.Web.Http.WebHost after published to Azure web site

后端 未结 15 1691
半阙折子戏
半阙折子戏 2020-12-07 10:39

I created a web project and it runs well in Visual studio. However, I got the following error after published it to azurewebsites. What can cause the issue?

相关标签:
15条回答
  • 2020-12-07 11:05

    I was missing several DLLs. Even if I manually copied them to the directory the next time I published they would disappear. Each one was already set to Copy Locally in VS. The fix for me was to set each one to Copy Locally false, save, build then set each one to copy locally true. This time when I published all of the DLLs published correctly. Strange

    0 讨论(0)
  • 2020-12-07 11:08

    If you are still looking for an answer, try checking this question thread. It helped me resolve a similar problem.

    edit: The solution that helped me was to run Update-Package Microsoft.AspNet.WebApi -reinstall from the NugGet package manager, as suggested by Pathoschild. I then had to delete my .suo file and restart VS, as suggested by Sergey Osypchuk in this thread.

    0 讨论(0)
  • 2020-12-07 11:10

    If you have multiple projects in your solution and one of your projects fails to build because of this error then ensure you have installed the WebApi Core nuget package in that project. Simply adding a reference to the System.Web.Http does not help, you need to install the correct nuget package into that project.

    I had multiple projects in my solution and WebApi Core was already installed in another project. I referenced the System.Web.Http assembly by right-clicking and ticking the assembly from the list and it did not work on Azure, though locally it would build okay. I had to remove the manual reference and add the WebApi Core nuget package to each project that needed the assembly reference.

    0 讨论(0)
  • 2020-12-07 11:11

    Make sure the package version is equal across the solution. I just downgraded & upgraded Microsoft.AspNet.Mvc package across the solution and the problem solved.

    0 讨论(0)
  • 2020-12-07 11:13

    For me it started working after selecting "Remove additional files at destination" in File publish options under settings on the publish dialog.

    0 讨论(0)
  • 2020-12-07 11:13

    The dll is missing in the published (deployed environment). That is the reason why it is working in the local i.e. Visual Studio but not in the Azure Website Environment.

    Just do Copy Local = true in the properties for the assembly(System.Web.Http.WebHost) and then do a redeploy, it should work fine.

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