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:<
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"
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;
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
this resolved this issue by adding namespace to Global.asax.cs file.
using System.Web.Http;
this resolved the issue.
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>
GlobalConfiguration
class is part of Microsoft.AspNet.WebApi.WebHost
nuget package...Have you upgraded this package to Web API 2?