Skip to content

[HttpRoute] Multiple controllers defined with the same name but differing namespaces #56

@ericreis

Description

@ericreis

Hello, I'm getting the following error when I try to access and api method:

Multiple types were found that match the controller named 'Grupos'. This can happen if the route that services this request ('api/v{version}/{controller}/{action}/{id}') found multiple controllers defined with the same name but differing namespaces, which is not supported. The request for 'Grupos' has found the following matching controllers: STALoginService.Api.Controllers.Version2.GruposController STALoginService.Api.Controllers.Version1.GruposController

Here is my MapHttpRoute:

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

Also, here is my project structure:

ApiProject
│
└─── Controllers
│   │
│   └─── Version1
│       │   GruposController.cs
│   │
│   └─── Version2
│       │   GruposController.cs

I learned about this package in the following video: https://www.youtube.com/watch?v=h0ui2KIVcaE and he uses the same class name but in different namespaces.

namespace STALoginService.Api.Controllers.Version1
{
    public class GruposController : ApiController
    {
        ...
    }
}
namespace STALoginService.Api.Controllers.Version2
{
    public class GruposController : ApiController
    {
        ...
    }
}

Does anyone had the same problem? Knows any fix?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions