I have been forced to upgrade Microsoft.AspNet.WebApi.Client and Microsoft.AspNet.WebApi.Core from version 5.0.0.0 to 5.2.0.0 due to a dependency on another project and now my API is throwing the error "A direct route cannot use the parameter 'controller'. Specify a literal path in place of this parameter to create a route to a controller".
The error gets thrown on initialisation of the HttpConfiguration within Global.asax.cs when calling
GlobalConfiguration.Configure(WebApiConfig.Register);
It seems to be the Core library that is causing the problem. When I updated just the Client it didn't throw the error.
I noticed that if I comment out the route attributes from all controllers within the project then it no longer throws the error, e.g.
[Route("api/storage/series/{series}/documentId/{documentId}")]
However removing these is not a viable solution due to the number of dependent applications.
On Google/Binging the error there's pretty much zero useful information on it. Can anyone offer any insight on this error and suggest how I might go about fixing it?
Figured this out, or rather my colleague did. It seems obvious now if you look at the error. It was due to the route attributes on some of our controllers (just not the example that I used in the question) containing {controller}. e.g.
[Route("api/{controller}/editGroups")]
Changing this to use the hardcoded controller name, as shown below, fixed the problem.
[Route("api/documents/editGroups")]
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