Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A route named 'MS_attributerouteWebApi' is already in the route collection

Tags:

I recently added Microsoft.AspNet.WebApi.WebHost to a MVC WebAPI project which would allow me to use the [Route("api/some-action")] attribute on my action. I solved some errors using this article but can't solve the third error below. Added solved errors below to get feedback if I did anything wrong.

First Error: No action was found on the controller 'X' that matches the name 'some-action'
Solution: Added config.MapHttpAttributeRoutes(); to WebApiConfig.cs Register method.

Second Error: System.InvalidOperationException The object has not yet been initialized. Ensure that HttpConfiguration.EnsureInitialized() is called in the application's startup code after all other initialization code.
Solution: Added GlobalConfiguration.Configure(WebApiConfig.Register); to Global.asax.cs Application_Start

Third Error: System.ArgumentException: A route named 'MS_attributerouteWebApi' is already in the route collection. Route names must be unique.
Solution = ?

I've already tried cleaning and deleting all DLLs from bin folder according to this post.

like image 848
joym8 Avatar asked Oct 15 '14 19:10

joym8


2 Answers

I had a similar problem and it was related to a copy paste error on my part where I added a copy of this line in my WebApiConfig.cs file:

config.MapHttpAttributeRoutes();

make sure you only have one of these.

like image 196
BraveNewMath Avatar answered Sep 30 '22 20:09

BraveNewMath


In the Global.asax, check how many times WebApiConfig.Register function has been called.

like image 39
JoeyZhao Avatar answered Sep 30 '22 19:09

JoeyZhao