Could not load file or assembly System.Web.Http.WebHost

Posted on September 17, 2018 by Suresh Kamrushi in C#

After deploying to IIS server from Visual Studio getting 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.

You can fixed by either of below steps:
Option 1: To Resolve issue you have to move “System.Web.Http.WebHost.dll” file in “bin” folder to IIS. And restart the server to reload everything again. Check the site should work.
Option 2: Follow below steps:
1) Go to “Solution Explorer” in Visula Studio.
2) Right Click on “System.Web.Http.WebHost” in “References” and select properties.
3) Update property “Local Copy” to “True”.
error
4) Clear and Build again to have DLL in bin folder.
5) Copy the “System.Web.Http.WebHost.dll” file in “bin” folder to IIS.
Application should work.
I am getting below errors (one after the another build) so I repeated the steps to update “Local Copy” to “True” and build and copied the DLL to IIS, it started working.

Could not load file or assembly 'System.Net.Http.Formatting, 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, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

Hope it helps someone to fix issue.

Tagged as ,