2014-09-10 56 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时出现此错误。我检查了“删除额外的文件”和“预编译”,这是默认未选中,它有帮助。我没有尝试任何其他选项。