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.
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.
In the Global.asax, check how many times WebApiConfig.Register
function has been called.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With