Asp.net-Mvc-4

無法載入文件或程序集“System.Web.Http.WebHost,版本=4.0.0.0,文化=中性,PublicKeyToken=31bf3856ad364e35”

  • October 23, 2014

在 Visual Studio 2012 中,我創建了一個 ASP.NET MVC 4 項目,其中目標框架是 .NET Framework 4.5。當我將項目部署到 Web 伺服器時,它給出了以下錯誤:

   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

檢查已部署項目的 bin 文件夾。它應該包含 System.Web.Http.WebHost.dll。如果此 dll 在此文件夾中,請檢查它的版本。如果不是 4.0.0.0,那麼您應該部署版本 4.0.0.0 或更改您的網路配置以使用其他版本(由於依賴關係,這不是一個好主意)

我今天在部署期間遇到了同樣的問題。我能夠通過將程序集標記為要復製到部署文件來修復它。

為此,在我的 Visual Studio 項目中,選擇System.Web.Http.Webhost引用中的程序集並將“複製本地”屬性更改為 True。對於缺少的其他一些程序集,我不得不重複此操作。

感謝這個網站的提示 - <http://haacked.com/archive/2008/11/03/bin-deploy-aspnetmvc.aspx/>

引用自:https://stackoverflow.com/questions/26533868