2014-09-10 55 views
5

使用Visual Studio 2013,我將一個混合的Asp.Net Webforms/MVC 3/Framework 4.0 Web應用程序遷移到Asp.Net Webforms/MVC 5.2.2/Framework 4.5 0.1。System.Web.WebPages中的MethodAccessException將mvc 3遷移到mvc 5

我跟着這些鏈接中列出的步驟:

http://www.asp.net/mvc/tutorials/mvc-5/how-to-upgrade-an-aspnet-mvc-4-and-web-api-project-to-aspnet-mvc-5-and-web-api-2

http://www.asp.net/signalr/overview/signalr-20/getting-started-with-signalr-20/upgrading-signalr-1x-projects-to-20

當我跑在Visual Studio中的應用程序,我得到這個錯誤:

Attempt by security transparent method 'System.Web.WebPages.Administration.SiteAdmin.RegisterAdminModule()' to access security critical method 'System.Web.WebPages.ApplicationPart..ctor(System.Reflection.Assembly, System.String)' failed.

我曾嘗試這些建議,我在StackOverflow找到,但沒有解決問題:

  1. 清除bin文件夾並重建
  2. 安裝Nuget包Microsoft.Aspnet.WebHelpers。
  3. 確保System.Web.Mvc和System.Web.WebPages的所有web.config引用指向正確的版本(分別爲5.2.2.0和3.0.0.0)。

有關如何找到此錯誤的原因的任何建議將不勝感激。

錯誤的完整堆棧跟蹤:

[MethodAccessException: Attempt by security transparent method 'System.Web.WebPages.Administration.SiteAdmin.RegisterAdminModule()' to access security critical method 'System.Web.WebPages.ApplicationPart..ctor(System.Reflection.Assembly, System.String)' failed.] 
    System.Web.WebPages.Administration.SiteAdmin.RegisterAdminModule() +96 
    System.Web.WebPages.Administration.PreApplicationStartCode.Start() +41 

[InvalidOperationException: The pre-application start initialization method Start on type System.Web.WebPages.Administration.PreApplicationStartCode threw an exception with the following error message: Attempt by security transparent method 'System.Web.WebPages.Administration.SiteAdmin.RegisterAdminModule()' to access security critical method 'System.Web.WebPages.ApplicationPart..ctor(System.Reflection.Assembly, System.String)' failed..] 
    System.Web.Compilation.BuildManager.InvokePreStartInitMethodsCore(ICollection`1 methods, Func`1 setHostingEnvironmentCultures) +559 
    System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +132 
    System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +102 
    System.Web.Compilation.BuildManager.ExecutePreAppStart() +153 
    System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +516 

[HttpException (0x80004005): The pre-application start initialization method Start on type System.Web.WebPages.Administration.PreApplicationStartCode threw an exception with the following error message: Attempt by security transparent method 'System.Web.WebPages.Administration.SiteAdmin.RegisterAdminModule()' to access security critical method 'System.Web.WebPages.ApplicationPart..ctor(System.Reflection.Assembly, System.String)' failed..] 
    System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9913572 
    System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101 
    System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254 
+0

您是否嘗試過安裝Microsoft.AspNet.WebPages.Data包? – Carl 2014-09-10 21:47:25

+0

是的,Microsoft.AspNet.WebPages.Data軟件包已安裝。 – 2014-09-11 14:30:03

回答

11

問題是Web應用程序引用了System.Web.Administration.dll的(Framework 1)版本,我認爲這是因爲此引用在幾年前需要從應用程序從Web表單移動到混合webforms/MVC 3.

我刪除了此引用並且問題消失。顯然這個DLL不再使用。我假設運行時是從這個DLL中取出System.Web.Administration的衝突版本,而不是使用新版本。

+0

這個答案只是爲我節省了幾個小時。謝謝 – Ian1971 2014-10-30 15:45:01

+0

你是如何刪除參考的? – e4rthdog 2015-01-21 06:36:36

+2

@ e4rthdog,展開解決方案資源管理器中的「References」節點,找到System.Web.Administration.dll,右鍵單擊它,選擇「刪除」 – 2015-01-21 13:26:45

2

當我有這個問題,我也不得不刪除OBJ文件夾的內容。

+0

感謝您的建議,但刪除obj文件夾不能解決它。我刪除了obj,bin和框架Temporary ASP.net文件,甚至嘗試了重新啓動。 – 2014-09-11 14:31:03

7

我在Asp.Net Webforms/MVC 5.2.2/Framework 4.5.1上遇到同樣的錯誤。當我發佈到Azure(它在localhost上正常工作)。

的溶液,從http://craigwilson.id.au/2014/03/18/azurewap-system-methodaccessexception-attempt-by-security-transparent-method/獲得的是:

  1. 安裝軟件包Microsoft.AspNet.WebHelpers。從包管理控制檯中運行以下命令:

    安裝,包裝-Id Microsoft.AspNet.WebHelpers

  2. 檢查部署選項位於發佈「目的地刪除其他文件」 - >設置 - >文件發佈選項

+3

「刪除目的地的其他文件」是什麼導致我的問題。我認爲在默認的Azure ASP.NET Web App中有一些較舊的DLL需要刪除。 – AaronLS 2016-06-16 17:54:52

0

我從一個模板創建了一個新的網站,並且在將網站發佈到Azure時出現此錯誤。我檢查了「刪除額外的文件」和「預編譯」,這是默認未選中,它有幫助。我沒有嘗試任何其他選項。