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

nzondlo picture nzondlo · Nov 26, 2013 · Viewed 154.7k times · Source

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:

WebApiConfig.Register(GlobalConfiguration.Configuration);

to

GlobalConfiguration.Configure(WebApiConfig.Register);

in the global.asax file. Yet this is giving me an error when I try to build:

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

My project is currently on MVC 5 and Web Api 2 and .NET 4.5.1, yet I think System.Web.Http still thinks it's the .NEt 4.0 version.

How can I go about fixing this?

Thank you.

Edit:

Here are my assembly bindings:

<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>

Everything commented out after the top was commented because I was getting the error:

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.

and getting rid of the hard bindings was fixing that.

Answer

Tyrone Moodley picture Tyrone Moodley · Feb 2, 2014

It needs the system.web.http.webhost which is part of this package. I fixed this by installing the following package:

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

or search for it in nuget https://www.nuget.org/packages/Microsoft.AspNet.WebApi.WebHost/5.1.0