Attempt by security transparent method 'System.Web.Http.GlobalConfiguration.get_Configuration()' to access security critical type 'System.Web.Http.HttpConfiguration' failed.
After doing a new deploy on our IIS server, we got the following error when we tried to start our ASP.NET MVC application:
System.TypeAccessException: Attempt by security transparent method 'System.Web.Http.GlobalConfiguration.get_Configuration()' to access security critical type 'System.Web.Http.HttpConfiguration' failed.
This rather obscure error didn’t ring a bell. And the explanation was not very helpfull.
When we looked at what had changed between this version and a previous version of the application, we noticed that WebApi was added to the solution. The NuGet package.config showed us that one of the packages had a rather different version:
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.6" targetFramework="net47" />
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.6" targetFramework="net47" />
<package id="Microsoft.AspNet.WebApi.WebHost" version="4.0.30506" targetFramework="net47" />
So we did a package upgrade to align all packages to the same version. After doing that, the error message disappeared.