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

asp.net-mvc-4dependenciesrazor

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?

Best Answer

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

Related Topic