Click here to Skip to main content
15,916,379 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello all,

I was trying to create a web-api-selfhost application, But ended up with an exception. Here is my code which caused the error.
C#
var config = new HttpSelfHostConfiguration("http://localhost:8080");

config.Routes.MapHttpRoute("API Default", "api/{controller}/{id}",new { id = RouteParameter.Optional });//This line caused error

            using (HttpSelfHostServer server = new HttpSelfHostServer(config))
            {
                server.OpenAsync().Wait();

                Console.WriteLine("Press Enter to quit.");
                Console.ReadLine();
            }

This is the exception which I have received.

C#
The type 'System.Web.Routing.RouteCollection' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

Should I import any other namespace? Any help on this would be appreciated.

Thanks & Regards
Sebastian
Posted
Updated 17-May-12 18:20pm
v2
Comments
Sebastian T Xavier 16-May-12 9:00am    
I have referred System.Web.Routing, But I can't use it in code...

1 solution

I have solved this myself, by adding system.web as a reference.

Thanks
Sebastian
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900