Suppose you have started a MVC 4 Project and wanted to update it to MVC 5. After Upgrading when you run the application, you will get the 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 Error follow these steps :
Step 1: Try installing Microsoft.AspNet.WebHelpers from NuGet
Install-Package -Id Microsoft.AspNet.WebHelpers
After installing Microsoft.AspNet.WebHelpers from NuGet very likely that you will get another error like "Could not load file or assembly 'WebMatrix.Data, Version=18.104.22.168, 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)."
If you get the above error go to Step 2.
Step 2: Try installing Microsoft.AspNet.WebPages.Data
That's it done. Now you can open your application and it will work as expected. If after doing above steps you are getting the same error, please let us know.
Please Like and Share the Blog, if you find it interesting and helpful.