我最近安装了 WebApi OData 5.0 框架的预发布版本,以使用新的 $expand 支持。一切正常,但我在 App_Start 上遇到了一个奇怪的异常。
Attempt by security transparent method
'System.Web.Http.GlobalConfiguration.get_Configuration()'
to access security critical type 'System.Web.Http.HttpConfiguration' failed.
源错误:
Line 12: protected void Application_Start()
Line 13: {
Line 14: WebApiConfig.Register(GlobalConfiguration.Configuration); // <--
Line 15: }
堆栈跟踪:
[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
API.WebApiApplication.Application_Start() in Global.asax.cs:14
[HttpException (0x80004005): Attempt by security transparent method 'System.Web.Http.GlobalConfiguration.get_Configuration()' to access
security critical type 'System.Web.Http.HttpConfiguration' failed.]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +12863325
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +175
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +304
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +404
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +475
[HttpException (0x80004005): 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) +12880068
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +159
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +12721257
谷歌透露的很少。