Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I resolve the error "Attempt by security transparent method 'System.Web.Http.GlobalConfiguration.get_Configuration()

I have created a solution with two projects: A MVC 4 and a Class Library. The solution compiles and runs fine. I then install-package 'Microsoft.AspNet.WebApi.OData -pre to pull in OData WebApi functionality. When I do, I get the following error at runtime:

Attempt by security transparent method 'System.Web.Http.GlobalConfiguration.get_Configuration()' to access security critical type 'System.Web.Http.HttpConfiguration' failed.

When WebApiConfig.Register(GlobalConfiguration.Configuration) runs in Global.asax

Once I do, uninstalling the package doesn't seem to fix. It removes the OData components obviously, but then leaves whatever assembly is causing this. removing with -RemoveDependencies removes ALL WebApi references in the library, and I'm unable to get it back in a working state.

What package hell am I in and how can I enable WebApi OData in a vanilla MVC4 app?

like image 862
Daniel Avatar asked Aug 27 '13 22:08

Daniel


1 Answers

It's a mismatch on the assemblies for the given version of WebAPI. Mine was failing because I was referencing a mismatched version of System.Web.Http.WebHost. So you can...

  1. Install the latest WebAPI from NuGet

    -OR-

  2. Make sure all your Microsoft.AspNet.WebApi.* packages are on the same version

like image 82
Nexxas Avatar answered Oct 11 '22 19:10

Nexxas