1
votes

I cannot call an HttpConfiguration extension method:

using System.Configuration;
using System.Web.Http;
...
      var config = new HttpConfiguration();
      config.MapHttpAttributeRoutes();  // <-- error

Error: 'System.Web.Http.HttpConfiguration' does not contain a definition for 'MapHttpAttributeRoutes' and no extension method 'MapHttpAttributeRoutes' accepting a first argument of type 'System.Web.Http.HttpConfiguration' could be found (are you missing a using directive or an assembly reference?)

I tried both with System.Web.Http version 4 and 5, and with ".NET Framework 4.5.2" and ".NET Framework 4".

What am I missing?

Reference

2
Its working fine for me. var config = new System.Web.Http.HttpConfiguration(); config.MapHttpAttributeRoutes();sam
@Pietro, make sure you have a reference to Assembly System.Web.Http.dll in your project where that code is being executed. Also try clearing bin folder and then rebuilding projectNkosi
@Nkosi, I have it selected. Just a doubt about its version. I have: System.Web v. 4.0, System.Web.Http v. 4.0 and System.Web.Http.Owin v. 5.2.3. I can System.Web.Http v. 5.2.3 (to match Owin), but no System.Web > 4.0. Could this be an issue?Pietro
@Pietro, yes. use v5.2.3.0 of System.Web.HttpNkosi
@Nkosi, I did it, and I also upgraded System.Web.Http.Formatting. It now works. Thank you.Pietro

2 Answers

1
votes

Make sure you have a reference to Assembly System.Web.Http.dll, v5.2.3.0 in your project where that code is being executed. HttpConfigurationExtensions.MapHttpAttributeRoutes was added to ASP.NET Web API 2.2 which requires the above mentioned version of the assembly.

0
votes

Fixed this problem (strictly related to this one) specifying in Project > Reference Manager:

Microsoft.Owin  2.0.2.0
Owin  1.0.0.0
System.Net.Http.Formatting  5.2.3.0
System.Web  4.0.0.0
System.Web.Http  5.2.3.0
System.Web.Http.Owin  5.2.3.0