使用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
我跟着這些鏈接中列出的步驟:
當我跑在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找到,但沒有解決問題:
- 清除bin文件夾並重建
- 安裝Nuget包Microsoft.Aspnet.WebHelpers。
- 確保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
您是否嘗試過安裝Microsoft.AspNet.WebPages.Data包? – Carl 2014-09-10 21:47:25
是的,Microsoft.AspNet.WebPages.Data軟件包已安裝。 – 2014-09-11 14:30:03