Sebazzz/SDammann.WebApi.Versioning

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

Opened this issue · 7 comments

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?

Which version of the lib are you using?

Version 2.8. Got it from NuGet.

Try version 3.x instead. Some incompatibilities in Web API have occurred and this is fixed in version 3.

Is it in NuGet? I only found 2.8

There is a prerelease available. Sorry for the confusion.

Oh, thank you, no problem. So this was a bug and it is fixed in this prerelease (Multiple controller with the same name but in different namespaces) ?

Yes, it should be fixed in the prerelease.