a blog for those who code

Thursday, 2 April 2015

How to fix System.MethodAccessException in ASP.NET MVC Application

In this post we are going to explain how to fix System.MethodAccessException: Attempt by security transparent method 'WebMatrix.WebData. PreApplicationStartCode.Start()' to access security critical method 'System. Web.WebPages.Razor.WebPageRazorHost.AddGlobalImport(System.String)' failed.

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=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)."


If you get the above error go to Step 2.

Step 2: Try installing Microsoft.AspNet.WebPages.Data

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

No comments:

Post a Comment