Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm creating a WepApi on visual studio 2010, I've use NuGet for the api. Now when I'm registering the API in the Global File im getting the following error. The code below is found in the application_Start of the api.

protected void Application_Start(object sender, EventArgs e)
        {
            log4net.Config.XmlConfigurator.Configure();
            RouteTable.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = System.Web.Http.RouteParameter.Optional }
            );
        }

The following error is being given on $RouteTable.Routes.MapHttpRoute - Instance argument:

cannot convert from 'System.Web.Routing.RouteCollection' to 'System.Web.Http.HttpRouteCollection'

Any suggestions why this error is given?

share|improve this question

2 Answers 2

You need to use

GlobalConfiguration.Configuration.Routes.MapHttpRoute

instead of

RouteTable.Routes.MapHttpRoute
share|improve this answer
    
The GlobalConfiguration is not found in the Global file –  Xupla May 10 '13 at 10:35
    
GlobalConfiguration is part of the System.Web.Http namespace. You should have a reference to this in your Global.asax file. –  Jon Susiak May 10 '13 at 10:45

DoNo if it applies to VS 2010. But add following ref in global

using System.Net.Http;
using System.Web.Http;
using System.Web.Http.WebHost;
using System.Web.Routing;
share|improve this answer
    
What does DoNo mean? Do you mean "don't know"? –  Jonathan Wakely Mar 9 at 11:57
    
yeap................... –  Radek82 Mar 9 at 12:07
    
Then please edit your question to say that. Please use English on StackOverflow, not meaningless abbreviations. –  Jonathan Wakely Mar 9 at 12:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.