Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Attempt by 'System.Web.Mvc.PreApplicationStartCode.Start()' to critical method 'System.Web.WebPages.Razor.PreApplicationStartCode.Start()' failed

My application was working fine and after I did some upgrades I am getting this error.

Server Error in '/' Application.


Attempt by security transparent method 'System.Web.Mvc.PreApplicationStartCode.Start()' to access security critical method 'System.Web.WebPages.Razor.PreApplicationStartCode.Start()' failed. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.MethodAccessException: Attempt by security transparent method 'System.Web.Mvc.PreApplicationStartCode.Start()' to access security critical method 'System.Web.WebPages.Razor.PreApplicationStartCode.Start()' failed.

Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding 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 cannot remember the updates I did. Is there a way to fix this?

like image 205
TylarBen Avatar asked Nov 13 '13 10:11

TylarBen


3 Answers

I think the issue has been solved, but if not, use this package from Nuget:

Install-Package Microsoft.AspNet.Mvc -Version 5.0.0

I have wasted a day for this error but this single line has done the work for me

like image 96
Vivekh Avatar answered Nov 07 '22 20:11

Vivekh


tried . . . Install-Package Microsoft.AspNet.Mvc -Version 5.0.0

and. . . Install-Package -Id Microsoft.AspNet.WebHelpers

both with no success, finally had to update all packages via nuget. . worked!!

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

If you're using visual studio open the nuget packages windows and run Update-Package, this will update all your dll to the last version. If it still 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

like image 44
defcde Avatar answered Nov 07 '22 19:11

defcde


I got this error when deploying a site where Mvc had been upgraded from 4 to 5 but I had not updated web.config.

Changing from 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>

to this:

<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.

like image 10
Fredrik Stolpe Avatar answered Nov 07 '22 20:11

Fredrik Stolpe