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.

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.

 

Scenario

I had a Visual Studio 2013 project using MVC4. The application was working fine in my local machine. But when I deployed the application using FileSystem( in this method all the files for the project gets copied to a folder on your local machine, then you can copy all these files to your webhost and your application should start working.)

 

I got the following error when I deployed the application using this method.

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.

 

How to Fix it?

I searched on the web for  some time to get the answer and in the end I discovered that the System.Web.HTTP.WebHost.DLL file was not being copied to my published folder and hence the error.

1. Go to the solution Explorer in Visual Studio

2. Go to the References

3. Right Mouse Click on the System.Web.HTTP.WebHost entry  to check its prooperties and I found that COPY LOCAL proeprty was set to false and hence the file was not being copied to my published folder.

4. I changed the COPY LOCAL to true and then the file gets copied to  my published folder and gets deployed correctly.

My Best-Answer.net