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".
PackageManagerConsole

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
PackageManagerConsoleWindow
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.


Comments



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: