I have 2 areas with 2 API controllers that have the same AI controller name, but different namespaces and which are configured via 2 different MapHttpRoute() calls with their unique names and routes. They also compile successfully without an issue. However, there are matching action methods in both and when I make a call to one I get back the exception below.
It's clear from the exception message that it's not supported but is there an elegant resolution so I don't have to name my API controllers uniquely despite being in separate namespaces?
Exception:
Multiple types were found that match the controller named 'SomethingApi'. This can happen if the route that services this request ('route-one/api/something/{action}') found multiple controllers defined with the same name but differing namespaces, which is not supported.
Route example:
public static void RegisterApiRoutes(HttpConfiguration config)
{
// URL: /route-one/api/something/
config.Routes.MapHttpRoute(
"RoutOne.Api.Something",
"route-one/api/something/{action}",
new { controller = "SomethingApi" }
);
}
Routes in both namespaces are called from the project's WebApiConfig:
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
RouteOneAreaRegistration.RegisterApiRoutes(config);
RouteTwoAreaRegistration.RegisterApiRoutes(config);
}
}