GenesysStack.com
RSS

Blog posts of '2015' 'December'

How-to fix: Attempt by security transparent method WebMatrix.WebData.PreApplicationStartCode.Start()

Visual Studio compile and runtime error: Attempt by security transparent method ‘WebMatrix.WebData.PreApplicationStartCode.Start()’ to access security critical method ‘System.Web.WebPages.Razor.WebPageRazorHost.AddGlobalImport(System.String)’ failed.

After upgrading Visual Studio to 2015, and projects from MVC 4.x to MVC 5.x, a few projects threw the following compile time and/or runtime error: Attempt by security transparent method ‘WebMatrix.WebData.PreApplicationStartCode.Start()’ to access security critical method ‘System.Web.WebPages.Razor.WebPageRazorHost.AddGlobalImport(System.String)’ failed.

To fix this initial error, upgrade WebHelpers via Nuget:

Install-Package Microsoft.AspNet.WebHelpers

Then it is likely you will receive this error after the nuget command: Could not load file or assembly 'WebMatrix.Data, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

To fix this new error, upgrade WebPages via Nuget:

Install-Package Microsoft.AspNet.WebPages.Data

Hope this helps!