0

I am trying to deploy a MVC Web API solution on the server. The server has Windows 2012 R2 operating system. This is MVC 4 based Web API solution. The server has .Net 4.0 framework installed. Except this server machine the solution has been deployed and working fine as expected. NOTE: those other machines has Visual Studio installed.

My issue here is - no matter whichever method I am applying, either solution itself or publish the solution, it is not working and giving below error.

Could not load file or assembly 'System.Web.Http.WebHost, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IO.FileNotFoundException: Could not load file or assembly 'System.Web.Http.WebHost, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

The stack trace says: [FileNotFoundException: Could not load file or assembly 'System.Web.Http.WebHost, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.] OSCARService.WebApiApplication.Application_Start() +0

[HttpException (0x80004005): Could not load file or assembly 'System.Web.Http.WebHost, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.] System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +544 System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +186 System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172 System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +402 System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +343

[HttpException (0x80004005): Could not load file or assembly 'System.Web.Http.WebHost, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.] System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +579 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +112 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +716

I tried finding this file (System.Web.Http.WebHost) in the framework directory but am unable to find this specific file.

I wonder Is this file necessarily required to be available physically?

I also tried setting System.Web.Http DLL to "CopyLocal='True'" but didn't work.

I already tried looking for similar situation/questions-answers here, but couldn't really get any direction.

I'd appreciate if anyone could provide direction here to my issue.

Binoy
  • 390
  • 5
  • 19
  • Are you using `Web API 2.2`? In that case, `System.Web.Http.WebHost` is part of `Microsoft.AspNet.WebApi.WebHost` nuget package. Please consider reinstalling this package by `Install-Package Microsoft.AspNet.WebApi.WebHost` – Nameless May 11 '17 at 09:29
  • @AjayAradhya: I am not sure. In my packages.config the line says: `` – Binoy May 11 '17 at 15:50
  • After spending good time on researching, I thought to go by manual approach. On local machine where I have Visual Studio, I found a reference of `System.Web.Http.WebHost` DLL from "Packages" directory. From that folder I copied the .dll and just pasted inside server's bin directory. I am quite sure there must be the way to "re-install" such NuGet packages outside/without visual studio. But for now I made this work. I will post my answer if I find or come across such utility. – Binoy May 11 '17 at 17:55
  • 1
    I did a bit of research and tried myself below links to install a package through Nuget CLI (Command Line Interface). I referred below links to make it work. 1. https://learn.microsoft.com/en-ca/nuget/tools/nuget-exe-cli-reference 2. http://blog.davidebbo.com/2011/01/installing-nuget-packages-directly-from.html – Binoy May 11 '17 at 19:08

2 Answers2

1

I fixed this by reinstalling the NuGet package, which corrects broken dependencies. From the package manager, try running this command

Update-Package Microsoft.AspNet.WebApi -reinstall

Nameless
  • 1,026
  • 15
  • 28
  • 1
    On server machine where I try to deploy the service has no visual studio installed, can you provide direction how could I reinstall the NuGet package and correct the missing dependencies? – Binoy May 11 '17 at 15:37
  • this is the best way to solve this – DanielV Sep 09 '20 at 08:20
0

Check the bin folder of your deployed project. It should contain System.Web.Http.WebHost.dll. If this dll is in this folder, check the version. If it isn't 4.0.0.0, then you should deploy version 4.0.0.0. If you are using nuget packages, check your packages.config else check your web.config if you have the right version installed.

Hope this helps

g.005
  • 396
  • 1
  • 12