'Multiple types were found that match the controller named "X"' between 2 projects

400 Views Asked by At

I have 2 projects in the same solution.

--PublicSite
----Apis
------PrivateApi

--ModelingSite
----Apis
------PrivateApi

I am getting this error :

Multiple types were found that match the controller named 'Courts'. This can happen if the route that services this request ('api/v1/{controller}/{id}') found multiple controllers defined with the same name but differing namespaces, which is not supported.

The request for 'Courts' has found the following matching controllers: PublicSite.Apis.Controllers.CourtsController ModelingSite.Apis.Controllers.ErrorHandling.CourtsController

This issue comes from having a reference of ModelingSite.Apis.PrivateApi in the PublicSite.Apis.PrivateApi which I have to keep for the data models as I am using web requests to get data from the ModelingSite api.

How do I make the web api not include the "wrong" controllers in its mapping?

This is my current WebApiConfig.cs

namespace PublicSite.Apis
{
    public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services

            // Web API routes
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/v1/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

            // default Json response
            config.Formatters.Remove(config.Formatters.XmlFormatter);
            config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));
        }
    }
}
0

There are 0 best solutions below