AccessException method inside System.Web.WebPages porting mvc 3 to mvc 5

Using Visual Studio 2013, I migrated the Asp.Net Webforms / MVC 3 / Framework 4.0 hybrid web application to Asp.Net Webforms / MVC 5.2.2 / Framework 4.5.1.

I followed the steps described in these links:

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

When I run the application in visual studio, I get this error:

The transparent security method 'System.Web.WebPages.Administration.SiteAdmin.RegisterAdminModule ()' attempted to access the critical critical security method 'System.Web.WebPages.ApplicationPart..ctor (System.Reflection.Assembly, System.String)' not managed.

I tried these suggestions that I found on StackOverflow, but no one fixes the problem:

  • empty bin folder and rebuild
  • Install the Nuget Microsoft.Aspnet.WebHelpers package.
  • Make sure that all web.config links from System.Web.Mvc and System.Web.WebPages point to the correct version (5.2.2.0 and 3.0.0.0 respectively).

Any advice on how to find the cause of this error would be greatly appreciated.

Full error stack error:

[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 
+5
source share
4 answers

The problem was that the web application had a link to the (Framework 1) version of System.Web.Administration.dll, I suppose because this link was needed a couple of years ago when the application switched from web forms to hybrid webforms / MVC 3 .

I deleted this link and the problem disappeared. Apparently this dll is no longer in use. I assume the runtime was extracting a conflicting version of System.Web.Administration from this library instead of using the new version.

+11
source

I was getting the same error in Asp.Net Webforms / MVC 5.2.2 / Framework 4.5.1. when I posted to Azure (it worked fine on the local host).

The solution obtained from http://craigwilson.id.au/2014/03/18/azurewap-system-methodaccessexception-attempt-by-security-transparent-method/ was as follows:

  • Install the Microsoft.AspNet.WebHelpers package. In the package management console, run the following command:

    Install-Package -Id Microsoft.AspNet.WebHelpers

  • Check the deployment option "Delete additional files at destination" located in the "Publish ..." → "Settings" → "File Publishing Options" section.

+7
source

When I had this problem, I also had to delete the contents of the obj folder.

+2
source

I created a new website from a template and was getting this error when the website was published to Azure. I checked “delete extra files” and “precompile” which are not checked by default, and that helped. I have not tried other options.

0
source

Source: https://habr.com/ru/post/1202280/


All Articles