gpt4 book ai didi

c# - GlobalConfiguration.Configure() 在 Web API 2 和 .NET 4.5.1 迁移后不存在

转载 作者:IT王子 更新时间:2023-10-29 03:31:50 26 4
gpt4 key购买 nike

我最近开始关注 this guide将我的项目迁移到 .NET 4.5.1 和 Web Api 2。

MS 开发人员 Rick Anderson 要求您做的第一件事就是更改:

WebApiConfig.Register(GlobalConfiguration.Configuration);

GlobalConfiguration.Configure(WebApiConfig.Register);

在 global.asax 文件中。然而,当我尝试构建时,这给了我一个错误:

Error 1 'System.Web.Http.GlobalConfiguration' does not contain a definition for 'Configure'

我的项目目前在 MVC 5 和 Web Api 2 以及 .NET 4.5.1 上,但我认为 System.Web.Http 仍然认为它是 .NEt 4.0 版本。

我该如何解决这个问题?

谢谢。

编辑:

这是我的程序集绑定(bind):

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31BF3856AD364E35" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0"/>
</dependentAssembly>
<!--
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="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 name="System.Web.Http" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-5.0.0.0" newVersion="5.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
</dependentAssembly> -->
</assemblyBinding>

在顶部被评论之后,所有的东西都被评论了,因为我得到了错误:

Warning 2 Found conflicts between different versions of the same dependent assembly that could not be resolved. These reference conflicts are listed in the build log when log verbosity is set to detailed.

摆脱硬绑定(bind)就是解决这个问题。

最佳答案

它需要作为这个包一部分的 system.web.http.webhost。我通过安装以下软件包解决了这个问题:

PM> Install-Package Microsoft.AspNet.WebApi.WebHost 

或者在nuget中搜索https://www.nuget.org/packages/Microsoft.AspNet.WebApi.WebHost/5.1.0

关于c# - GlobalConfiguration.Configure() 在 Web API 2 和 .NET 4.5.1 迁移后不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20226715/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com