Attempt by security transparent method 'System.Web.Http.GlobalConfiguration.get_Configuration()'
How to resolve the error:
Attempt by security transparent method 'System.Web.Http.GlobalConfiguration.get_Configuration()' to access security critical type 'System.Web.Http.HttpConfiguration' failed.
When I created a MVC4 application using Visual Studio 2012 on Windows 7 machine and added a data model and controller class which contains a method with Queryable attribute which is supported by OData. After installing ASP.NET Web API 2.1 OData from Manage Nuget Packages Manager window, when I ran the application I got the below error:
Attempt by security transparent method 'System.Web.Http.GlobalConfiguration.get_Configuration()' to access security critical type 'System.Web.Http.HttpConfiguration' failed.
In order to resolve this error, Please follow the below steps:
Step 1: In the Visual Studio project -> Go to Tools -> "Library Package Manager" -> "Package Manager Console".
This opens the Package Manager Console window at the bottom of the Visual Studio screen.
Step 2: Run the below command in the Package Manager Console window.
Update-Package Microsoft.AspNet.WebApi -Pre
This command updates the 'Microsoft.AspNet.WebApi' from version '4.0.20710.0' to '5.1.1' in your project.
Step 3: Now build the project and run the application. The above error should be resolved.