Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not load file or assembly 'System.Web.Http.WebHost, Version=4.0.0.0, Culture=neutral,PublicKeyToken=31bf3856ad364e35'

In Visual Studio 2012 I created an ASP.NET MVC 4 project where the target framework is the .NET Framework 4.5. When I deployed my project to a web server it gave the following 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.

Source Error: 


Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34237
like image 936
user1688401 Avatar asked Oct 23 '14 17:10

user1688401


3 Answers

I had the same issue today during deployment. I was able to fix it by marking the assembly to be copied to the deployment file.

In order to do this, in my Visual Studio project, select the System.Web.Http.Webhost assembly in your references and alter the 'Copy Local' property to True. I had to repeat this for a few other assemblies that were missing.

Thanks to this website for the tips - http://haacked.com/archive/2008/11/03/bin-deploy-aspnetmvc.aspx/

like image 132
Stan Hebben Avatar answered Nov 20 '22 14:11

Stan Hebben


Check the bin folder of your deployed project. It should contain System.Web.Http.WebHost.dll. If this dll is in this folder, check it version. If it isn't 4.0.0.0, then you should deploy version 4.0.0.0 or change your web config to use other version (not really good idea because of dependencies)

like image 24
IAfanasov Avatar answered Nov 20 '22 16:11

IAfanasov


Try to reinstall Microsoft.AspNet.WebApi package. Open Package Manager Console and type:

Update-Package Microsoft.AspNet.WebApi -reinstall

Be careful, this command will remove all dependencies and you will have to install them manually.

like image 12
Robert Avatar answered Nov 20 '22 14:11

Robert