2014-02-15 41 views
0

我已將ASP.NET應用程序升級到MVC 4.一切工作在我的本地計算機上。 但當我將應用程序部署到Web服務器,我得到了以下錯誤消息:升級後的ASP.NET MVC應用程序問題

Server Error in '/' Application. 
Could not load file or assembly 'System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) 
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.FileLoadException: Could not load file or assembly 'System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) 


Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

Assembly Load Trace: The following information can be helpful to determine why the assembly 'System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' could not be loaded. 


WRN: Assembly binding logging is turned OFF. 
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1. 
Note: There is some performance penalty associated with assembly bind failure logging. 
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog]. 


Stack Trace: 


[FileLoadException: Could not load file or assembly 'System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)] 
    System.Web.Mvc.PreApplicationStartCode.Start() +0 

[InvalidOperationException: The pre-application start initialization method Start on type System.Web.Mvc.PreApplicationStartCode threw an exception with the following error message: Could not load file or assembly 'System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040).] 
    System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +423 
    System.Web.Compilation.BuildManager.CallPreStartInitMethods() +306 
    System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +677 

[HttpException (0x80004005): The pre-application start initialization method Start on type System.Web.Mvc.PreApplicationStartCode threw an exception with the following error message: Could not load file or assembly 'System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040).] 
    System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9164848 
    System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +97 
    System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +256 

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1016 

的錯誤信息可以在這裏看到:http://dev.aishaudio.com

+0

謝謝糊狀 - 這是我的第一個問題 – softwarexpert

+0

如果您使用的包管理器,卸載Microsoft.AspNet.Mvc包,然後重新安裝,然後檢查 – Damith

+0

謝謝您的回答,但我已經做到這一點,並沒有幫助 – softwarexpert

回答

0

最可能的原因是因爲你引用那些文件只有在本地機器上,很可能在GAC中,所以當你部署到服務器時,它找不到它們。

看看你的MVC引用的屬性窗口,看看是否有任何GAC。

要解決此問題,請在引用的屬性窗口中將對System.Web.Mvc的引用標記爲「copy local = true」。然後,當您部署/構建安裝程序時,它會將引用的文件複製到bin文件夾中,因此將在服務器上可用。

對所有MVC文件重複此過程。

1

您需要將大量程序集部署到部署的應用程序的bin文件夾中。 See this blog post或谷歌的「部署mvc程序集」獲取更多信息。

+0

感謝您的回答,但我已將所有來自文章的文件放在Web服務器上。 – softwarexpert