SDammann.WebApi.Versioning icon indicating copy to clipboard operation
SDammann.WebApi.Versioning copied to clipboard

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

Open ericreis opened this issue 8 years ago • 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?

ericreis avatar Nov 18 '16 20:11 ericreis

Which version of the lib are you using?

Sebazzz avatar Nov 22 '16 19:11 Sebazzz

Version 2.8. Got it from NuGet.

ericreis avatar Nov 24 '16 20:11 ericreis

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

Sebazzz avatar Nov 25 '16 17:11 Sebazzz

Is it in NuGet? I only found 2.8

ericreis avatar Nov 28 '16 00:11 ericreis

There is a prerelease available. Sorry for the confusion.

Sebazzz avatar Nov 29 '16 17:11 Sebazzz

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) ?

ericreis avatar Dec 01 '16 13:12 ericreis

Yes, it should be fixed in the prerelease.

Sebazzz avatar Dec 01 '16 18:12 Sebazzz