gpt4 book ai didi

c# - System.Web.WebPages 中的 MethodAccessException 将 mvc 3 迁移到 mvc 5

转载 作者:太空狗 更新时间:2023-10-29 22:06:32 24 4
gpt4 key购买 nike

使用 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 中运行应用程序时,出现此错误:

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

最佳答案

问题是 Web 应用程序引用了 System.Web.Administration.dll 的(框架 1)版本,我猜是因为几年前当应用程序从 Web 表单迁移到混合表单时需要这个引用网络表单/MVC 3.

我删除了这个引用,问题就消失了。显然这个 dll 不再被使用。我假设运行时正在从这个 dll 中获取冲突版本的 System.Web.Administration,而不是使用新版本。

关于c# - System.Web.WebPages 中的 MethodAccessException 将 mvc 3 迁移到 mvc 5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25775234/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com