System.Web.WebPages中的MethodAccessException将mvc 3迁移到mvc 5
使用Visual Studio 2013,我将混合的Asp.Net Webforms / MVC 3 / Framework 4.0 Web应用程序迁移到Asp.Net Webforms / MVC 5.2.2 / Framework 4.5.1。
我按照这些链接中列出的步骤操作:
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中运行应用程序时,我收到此错误:
尝试通过安全透明方法’System.Web.WebPages.Administration.SiteAdmin.RegisterAdminModule()’来访问安全关键方法’System.Web.WebPages.ApplicationPart..ctor(System.Reflection.Assembly,System.String)’失败。
我尝试过在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
问题是Web应用程序引用了System.Web.Administration.dll的(Framework 1)版本,我假设因为几年前当应用程序从Web表单移动到混合webforms / MVC时需要这个引用3。
我删除了这个引用,问题就消失了。 显然这个dll不再使用了。 我假设运行时从此dll获取System.Web.Administration的冲突版本而不是使用新版本。
我在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/获得的解决方案是:
-
安装包Microsoft.AspNet.WebHelpers。 从包管理控制台运行以下命令:
Install-Package -Id Microsoft.AspNet.WebHelpers
-
检查位于发布… – >设置 – >文件发布选项的部署选项“删除目的地的其他文件”。
当我遇到这个问题时,我还必须删除obj文件夹的内容。
我已经从模板创建了一个新网站,并在网站发布到Azure时收到此错误。 我已经检查了“删除额外的文件”和“预编译”,这些文件在默认情况下未经检查,并且有所帮助。 我没有尝试任何其他选择。
上述就是C#学习教程:System.Web.WebPages中的MethodAccessException将mvc 3迁移到mvc 5分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请点击右边联系管理员删除。
如若转载,请注明出处:https://www.ctvol.com/cdevelopment/1001021.html