GlobalConfiguration.Configure() not present after Web API 2 and .NET 4.5.1 migration

后端 未结 11 1947
后悔当初
后悔当初 2020-12-02 08:24

I recently started following this guide to migrate my project to .NET 4.5.1 and Web Api 2.

The very first thing MS developer Rick Anderson asks you to do is change:<

相关标签:
11条回答
  • 2020-12-02 08:32

    GlobalConfiguration.Configure API is available in "Microsoft.AspNet.WebApi.WebHost" version="5.2.3"

    and not in "Microsoft.AspNet.WebApi.WebHost" version="4.0.0"

    0 讨论(0)
  • 2020-12-02 08:36

    As well as using Package manager console to get nuget to update the project with Install-Package Microsoft.AspNet.WebApi.WebHost for missing GlobalConfiguration,

    I needed Install-Package Microsoft.AspNet.WebApi.SelfHost for missing using System.Web.Http;

    0 讨论(0)
  • 2020-12-02 08:37

    You may want to check that your project has Microsoft.AspNet.WebApi.WebHost installed. As it turns out, in my case, Microsoft.AspNet.WebApi.WebHost was installed in another project, but not the particular project that needed it. In your packages.config, check that a line like this is there:

    <package id="Microsoft.AspNet.WebApi.WebHost" version="5.1.1" targetFramework="net45" />
    

    If that is not present, you don't have Microsoft.AspNet.WebApi.WebHost installed in your project. You can either install using Nuget Package Manager or through the Package Manager Console. To install from the Package Manager Console, run this command:

    Install-Package Microsoft.AspNet.WebApi.WebHost
    
    0 讨论(0)
  • 2020-12-02 08:41

    this resolved this issue by adding namespace to Global.asax.cs file.

    using System.Web.Http;

    this resolved the issue.

    0 讨论(0)
  • 2020-12-02 08:42

    If the issue remain after uninstalling and installing Microsoft.AspNet.WebApi.WebHost then also add followings in web.config for globalconfiguration to work

     <dependentAssembly>
            <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.2.0.0" />
          </dependentAssembly>
    
    0 讨论(0)
  • 2020-12-02 08:43

    GlobalConfiguration class is part of Microsoft.AspNet.WebApi.WebHost nuget package...Have you upgraded this package to Web API 2?

    0 讨论(0)
提交回复
热议问题