Reputation: 3131
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?
Upvotes: 29
Views: 37202
Reputation: 148
If this package don't exist from the answers above you can install it
install-package Microsoft.AspNet.WebApi
Upvotes: 3
Reputation: 59
I was facing same issue and fix is to use same version of "System.Web.Http.WebHost" as Syste.Web.Http which is 5.2.6
Upvotes: 5
Reputation: 184
I faced issue and I noticed, previous server code build with Release mode and I am uploading build with Debug mode code. So, I replaced with Release mode and then issue is resolved.
Upvotes: 0
Reputation: 161
I ran "update-package Microsoft.AspNet.WebApi" in the Package Manager Console in VS and worked like a charm.
Upvotes: 16
Reputation: 893
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...
Install the latest WebAPI from NuGet
-OR-
Make sure all your Microsoft.AspNet.WebApi.*
packages are on the same version
Upvotes: 35
Reputation: 81700
If you create an MVC 4 app from its template, then you are installing Web API 4.0. if you use
install-package 'Microsoft.AspNet.WebApi.OData -pre
You will be dependent on ASP.NET Web API 5.0 rc.
My suggestion is to use "Empty ASP.NET web application" template rather than MVC 4.0 template.
Upvotes: 11
Reputation: 6793
Do you need the pre-release version of web API OData? If so, you need to update all the other web API packages to match that version. If not, just do,
install-package 'Microsoft.AspNet.WebApi.OData
without the -pre
option
Upvotes: 3