1
Vote

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

description

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

This is my Owin startup:
    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            var configuration = GlobalConfiguration.Configuration;
            configuration.MapCodeRoutes(typeof (PingController));
        }
    }
Stacktrace:
[TypeAccessException: Attempt by security transparent method 'System.Web.Http.GlobalConfiguration.get_Configuration()' to access security critical type 'System.Web.Http.HttpConfiguration' failed.]
   System.Web.Http.GlobalConfiguration.get_Configuration() +0
   MvcCodeRouting.Web.Http.WebHost.PreApplicationStartCode.Start() in d:\foss\MvcCodeRouting\src\MvcCodeRouting.Web.Http.WebHost\PreApplicationStartCode.cs:35

[InvalidOperationException: The pre-application start initialization method Start on type MvcCodeRouting.Web.Http.WebHost.PreApplicationStartCode threw an exception with the following error message: Attempt by security transparent method 'System.Web.Http.GlobalConfiguration.get_Configuration()' to access security critical type 'System.Web.Http.HttpConfiguration' failed..]
   System.Web.Compilation.BuildManager.InvokePreStartInitMethodsCore(ICollection`1 methods, Func`1 setHostingEnvironmentCultures) +613
   System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +141
   System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +102
   System.Web.Compilation.BuildManager.ExecutePreAppStart() +157
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +531

[HttpException (0x80004005): The pre-application start initialization method Start on type MvcCodeRouting.Web.Http.WebHost.PreApplicationStartCode threw an exception with the following error message: Attempt by security transparent method 'System.Web.Http.GlobalConfiguration.get_Configuration()' to access security critical type 'System.Web.Http.HttpConfiguration' failed..]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9923088
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +90
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +261

comments

maxtoroq wrote Dec 3, 2015 at 4:37 PM

A quick Google search suggests it's a Web API versioning issue.

teyde wrote Dec 3, 2015 at 6:05 PM

Yes it is a versioning issue, but not on my side. It seems like the library is compiled against Web Api 4.0.0.0 which is pretty old by now.

The NuGet packages are also listed with no dependencies to Asp.NET Web Api, which is clearly false.

maxtoroq wrote Dec 4, 2015 at 12:47 AM

Are you using an assembly redirect from 4.0.0.0 to the version you are using?

teyde wrote Dec 7, 2015 at 6:30 PM

Good point. I have to check that next time...