Jas*_*ker 13 odata asp.net-mvc-4 asp.net-web-api
我最近安装了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.
Run Code Online (Sandbox Code Playgroud)
来源错误:
Line 12: protected void Application_Start()
Line 13: {
Line 14: WebApiConfig.Register(GlobalConfiguration.Configuration); // <--
Line 15: }
Run Code Online (Sandbox Code Playgroud)
堆栈跟踪:
[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
Run Code Online (Sandbox Code Playgroud)
谷歌揭示的很少.
S. *_*ran 23
按照给定的顺序在包管理器控制台中运行以下命令:
Uninstall-Package Microsoft.AspNet.Mvc.FixedDisplayModes
Update-Package Microsoft.AspNet.Mvc -Pre
Update-Package Microsoft.AspNet.WebApi -Pre
Update-Package Microsoft.AspNet.WebApi.Tracing
Run Code Online (Sandbox Code Playgroud)
现在,将以下更改应用于web.config:
在项目的Web.config中,将app setting webpages:version的值更新为3.0.0.0
在web.config中的部分运行时下,检查已配置的每个程序集的版本,并将其更新为添加到项目的程序集的版本.以下是我的web.config中的更新配置:
<运行>
<assemblyBinding的xmlns = "瓮:架构-微软-COM:asm.v1">
<dependentAssembly>
<assemblyIdentity名称= "System.Web.Helpers"公钥= "31bf3856ad364e35"/>
<bindingRedirect oldVersion ="1.0.0.0 -3.0.0.0" NEWVERSION = "3.0.0.0"/>
</ dependentAssembly>
<dependentAssembly>
<assemblyIdentity名称= "System.Web.Mvc"公钥= "31bf3856ad364e35"/>
<bindingRedirect oldVersion ="1.0.0.0-5.0. 0.0"newVersion ="5.0.0.0"/>
</ dependentAssembly>
<dependentAssembly>
<assemblyIdentity name ="System.Web.WebPages"publicKeyToken ="31bf3856ad364e35"/>
<bindingRedirect oldVersion ="1.0.0.0-3.0.0.0"newVersion ="3.0.0.0"/>
</ dependentAssembly>
<dependentAssembly>
<assemblyIdentity名称= "的EntityFramework"公钥= "b77a5c561934e089"/>
<bindingRedirect oldVersion = "0.0.0.0-5.0.0.0" NEWVERSION = "5.0.0.0"/>
</ dependentAssembly>
<dependentAssembly>
<assemblyIdentity名称= "WebGrease"公钥= "31bf3856ad364e35"/>
<bindingRedirect oldVersion = "0.0.0.0-1.3.0.0" NEWVERSION = "1.3.0.0"/>
</ dependentAssembly>
<dependentAssembly>
<assemblyIdentity名称="系统. Web.Http"publicKeyToken ="31bf3856ad364e35"culture ="中性"/>
<bindingRedirect oldVersion ="0.0.0.0-5.0.0.0"newVersion ="5.0.0.0"/>
</ dependentAssembly>
<dependentAssembly>
<assemblyIdentity名称= "System.Net.Http.Formatting"公钥= "31bf3856ad364e35"文化= "中性"/>
<bindingRedirect oldVersion = "0.0.0.0-5.0.0.0" NEWVERSION = "5.0.0.0"/>
</ dependentAssembly>
</ assemblyBinding>
</ runtime>
从Views文件夹中打开web.config.这里有三件事需要更新:
在configSections下,将Razor程序集的版本更新为3.0.0.0.
更新system.web.webPages.razor部分下的主机版本,将System.Web.Mvc.MvcWebRazorHostFactory的版本更新为3.0.0.0.
System.web的页面部分提到了一些版本号.将所有这些更新到版本5.0.0.0
如果安装了Web API帮助页面,请检查上面的程序集配置.
iam*_*ody 12
我有同样的错误.我只是稍微调整了Ravi的答案,发现通过更新/安装WebApi.OData 5.0.0-rc1包来更新WebApi包对我来说效果很好.我刚刚在包管理器上运行了这些:
Update-Package Microsoft.AspNet.WebApi -Pre
Install-Package Microsoft.AspNet.WebApi.OData -Version 5.0.0
Run Code Online (Sandbox Code Playgroud)
我猜测WebApi.OData包的预发行版本与新版本的WebApi包有一些依赖关系,Nuget无法将其作为依赖项进行检查.再说一遍,我在技术上是WebApi OData的新手,对包不太了解但是,是的,我可以使用$ expand和$ select功能运行项目,而不是GlobalConfiguration错误.:)