An attempt to "System.Web.Mvc.PreApplicationStartCode.Start ()" to the critical method "System.Web.WebPages.Razor.PreApplicationStartCode.Start ()" failed

My application worked fine, and after I made some updates, I get this error.

Server error in application "/".




An attempt to use the transparent security method " System.Web.Mvc.PreApplicationStartCode.Start() " to access the critical critical method " System.Web.WebPages.Razor.PreApplicationStartCode.Start() " failed. Description: An unhandled exception occurred during the execution of the current web request. View the stack trace for more information about the error and its occurrence in the code.

Exception Details: System.MethodAccessException : An attempt to use the transparent security method System.Web.Mvc.PreApplicationStartCode.Start() 'to access the critical critical security method System.Web.WebPages.Razor.PreApplicationStartCode.Start() ' failed.

Source Error : An unhandled exception was thrown during the execution of the current web request. Information about the origin and location of the exception can be identified using the exception stack trace below.

Version Information : Microsoft.NET Framework Version: 4.0.30319; ASP.NET Version: 4.0.30319.18055

I do not remember the updates I made. Is there any way to fix this?

+50
dependencies razor asp.net-mvc-4
Nov 13 '13 at
source share
14 answers

I think the problem is resolved, but if not, use this package from Nuget:

 Install-Package Microsoft.AspNet.Mvc -Version 5.0.0 

I spent a day on this error, but this one line did the job for me

+62
Dec 30 '14 at 6:10
source share

tried., Install-Package-Microsoft.AspNet.Mvc -Version 5.0.0 as well., Install-Package -Id Microsoft.AspNet.WebHelpers

both without success, finally had to update all packages through nuget., works !!

http://www.3dbuzz.com/forum/threads/202082-ASP-net-MVC-Error-before-application-start

"If you are using visual studio, open the nuget package windows and run Update-Package, this will update your entire dll to the latest version. If it still does not work, see this page: 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 "

+11
Jan 21 '14 at 10:00
source share
+5
Nov 13 '13 at 11:21
source share

I got this error when deploying a site on which Mvc was upgraded from 4 to 5, but I did not update web.config.

By changing this:

 <dependentAssembly> <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0- 4.0.0.0 " newVersion=" 4.0.0.0 " /> </dependentAssembly> 

:

 <dependentAssembly> <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0- 5.0.0.0 " newVersion=" 5.0.0.0 " /> </dependentAssembly> 

solved the problem for me.

+5
Apr 27 '16 at 11:22
source share

The same error also occurred to me. This has been fixed by installing the NuGet package.

  Install-Package -Id Microsoft.AspNet.WebHelpers 
+4
Dec 23 '13 at 5:28
source share

I had a similar problem and solved it based on the article Upgrading Razor 2.0 to 3.0 using Asp.net MVC by Anthony Fassett

In my Web.Config, the following code was missing:

 <dependentAssembly> <assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> </dependentAssembly> 
+4
Apr 16 '14 at 8:13
source share

To solve this problem, there are several solutions:

  • Follow the instructions to update your asp.net solution
  • Remember to remove the Microsoft-Web-Helpers dll and install the Microsoft.AspNet.WebHelpers nuget package

Then make sure that you have updated all your nuget packages (use the "Upgrade-Package") and check your dll in web.config.

The error is probably an action in the old DLL when you convert your project.

+1
Sep 05 '14 at 14:01
source share

In my case, installing nuget changed my Web.Config:

  <dependentAssembly> <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="1.0.0.0-5.1.0.0" newVersion="1.1.0.0" /> </dependentAssembly> 

newVersion="1.1.0.0" ** must be newVersion="5.1.0.0"

+1
Jan 21 '15 at 10:15
source share

Right click for project -> Nuget Package Management for a solution than find

Microsoft.AspNet.Mvc and Microsoft.Net.Compilers update the latest versions

+1
Feb 29 '16 at 9:48
source share

In my case, it was an incompatibility problem. I had theses pacakges:

  • Microsoft.AspNet.Mvc version 4.x
  • Microsoft.AspNet.Razor and Microsoft.AspNet.WebPages , version 3.x

I assume that upgrading Mvc to 5.x would work, but I needed to keep Mvc 4.x, so I had to downgrade Razor and Mvc to 2.x. To do this, you just need to install an older version, for example:

 Install-package Microsoft.AspNet.WebPages -version 2.0.30506 Install-Package Microsoft.AspNet.Razor -Version 2.0.30506 

After overriding these packages, the first error disappeared, but there was another error related to the problem in web.config . I had to change the binding binding for Razor:

 <dependentAssembly> <assemblyIdentity name="System.Web.Razor" ... /> <!--bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" /--> <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" /> </dependentAssembly> 

I don’t know why, but the binding redirection was not updated by the Nuget installation that was supposed to do this.

+1
Jun 07 '16 at 2:37
source share

I solved my problem by applying the "Install-Package Microsoft.AspNet.Mvc" command.

After that, I solved my project using the Web API.

+1
Aug 25 '17 at 17:12
source share

I got this error when I updated the NuGet package - Microsoft.AspNet.Web Pages ' version 3.2.3. I use VS2012, creating a new ASP.NET MVC 4 > web application with an Internet application template using Windows authentication or Windows Azure authentication.

The update may not be compatible with other components, and these other components should also be updated. Other answers suggest updating Microsoft.AspNet.Mvc , Microsoft.Net.Compilers and / or Microsoft.AspNet.WebHelpers .

0
Apr 22 '16 at 16:02
source share

I am working on an ASP.NET Web API project and get the same problem after adding the following nuget CacheCow.Server.EntityTagStore.SqlServer

He decided to install this

 Install-Package Microsoft.AspNet.Mvc 
0
Feb 07 '17 at 18:12
source share

Install-Package -Id Microsoft.AspNet.WebHelpers

Microsoft.AspNet.Mvc Installation Package -Version 5.0.0

It worked for me

0
Aug 21 '17 at 15:16
source share



All Articles