Thursday 4 June 2015

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

System.Web.Http.WebHost, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies

1.Make sure dll available in your bin folder or references added for  System.Web.Http.WebHost.

2.If not install it from NuGet package,

PM> Install-Package Microsoft.AspNet.WebApi
or reinstall
PM > Update-Package Microsoft.AspNet.WebApi -reinstall

3.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.
If you get the similar error i.e. some other assembly missing, then make that assembly to copylocal=true and redeploy, repeat this iteratively - if you are unsure of its dependencies.