2011-01-24 62 views
14

我創建新項目ASP.NET MVC 3 RTM和使用ASP.NET MVC的 更換參考3 的源代碼ASP.NET MVC 3 RTM項目中的這個錯誤是什麼?

,但是當我再次運行項目,得到此異常:

[A]System.Web.WebPages.Razor.Configuration.HostSection cannot be cast to [B]System.Web.WebPages.Razor.Configuration.HostSection. Type A originates from 'System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' in the context 'Default' at location 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.WebPages.Razor\v4.0_1.0.0.0__31bf3856ad364e35\System.Web.WebPages.Razor.dll'. Type B originates from 'System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' in the context 'Default' at location 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\2505c7ee\369315c5\assembly\dl3\f7bae428\d03eeed8_85bbcb01\System.Web.WebPages.Razor.DLL'.

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.

源錯誤:

Line 106:  internal static RazorWebSectionGroup GetRazorSection(string virtualPath) { 
Line 107:   // Get the individual sections (we can only use GetSection in medium trust) and then reconstruct the section group 
Line 108:   return new RazorWebSectionGroup() { 
Line 109:    Host = (HostSection)WebConfigurationManager.GetSection(HostSection.SectionName, virtualPath), 
Line 110:    Pages = (RazorPagesSection)WebConfigurationManager.GetSection(RazorPagesSection.SectionName, virtualPath) 

Source File: E:\GreenTour\webpages\src\System.Web.WebPages.Razor\WebRazorHostFactory.cs Line: 108

回答

13

此錯誤意味着您的應用程序的一部分正在使用您自己的源代碼副本作爲參考進行編譯,而在運行時它將在GAC中查找參考程序集。確保刪除了所有對GACed版MVC 3程序集的引用。這包括使用此公鑰令牌的web.config文件中的許多內容:31bf3856ad364e35。

0

雖然上面的線程是有用的。直到我創建了一個「虛擬」「基本」MVC 4應用程序,然後比較web.configs以查找任何更改之後,我纔得到工作。

13

我剛剛遇到同樣的問題,同時升級我的應用程序,問題是在位於views目錄中的web.config文件,我盲目地從舊應用程序(我的壞)複製這個。

我的解決方案,創建一個新的MVC 4應用程序,並從視圖目錄複製web.config到你的應用程序那有問題。

希望這有助於

+2

謝謝 - 您的評論「位於views目錄中的web.config文件」剛剛給了我一個「啊哈!」時刻。 – DaveHogan 2012-09-23 19:05:28

0

我解決了這個問題不是通過刪除所有引用與31bf3856ad364e35公鑰組件,因爲這涵蓋了很多不相關的組件。

相反,它應該通過更新所有的配置被固定爲2

  • System.Web.WebPages.Razor引用

    • System.Web.Mvc至4個
    • System.Web.WebPages至2

    請務必更新所有web.configs,包括View目錄中的web.configs。

  • 相關問題