Skip to content

Cannot run APIs with different controller names with same ControllerName attribute after migration #1033

@anime-shed

Description

@anime-shed

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I have migrated from
"Microsoft.AspNetCore.Mvc.Versioning" Version="5.1.0"
To
"Asp.Versioning.Mvc" Version="6.4.0"

But after this following has stopped working;

[Route("api/[controller]/[action]")]
[AllowAnonymous]
[ApiController]
[ControllerName("Attributes")]
public class InfoController : ControllerBase
{
    private readonly IEnumerable<EndpointDataSource> _endpointSources;

    public InfoController(IEnumerable<EndpointDataSource> endpointSources)
    {
        _endpointSources = endpointSources;
    }

    [HttpGet]
    public async Task<ActionResult> ListAllEndpoints()
    {
        var endpoints = _endpointSources
            .SelectMany(es => es.Endpoints)
            .OfType<RouteEndpoint>();
        var output = endpoints.Select(
            e =>
            {
                var controller = e.Metadata
                    .OfType<ControllerActionDescriptor>()
                    .FirstOrDefault();
                var action = controller != null
                    ? $"{controller.ControllerName}.{controller.ActionName}"
                    : null;
                var controllerMethod = controller != null
                    ? $"{controller.ControllerTypeInfo.FullName}:{controller.MethodInfo.Name}"
                    : null;
                return new
                {
                    Method = e.Metadata.OfType<HttpMethodMetadata>().FirstOrDefault()?.HttpMethods?[0],
                    Route = $"/{e.RoutePattern.RawText.TrimStart('/')}",
                    Action = action,
                    ControllerMethod = controllerMethod
                };
            }
                                     );

        return Ok(output);
    }
}

In the above:
image
image

Where As:
image
image

Expected Behavior

This should be working since I tried to follow guide.

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

8.0.100-rc.2.23502.2

Anything else?

ASP.NET Core : 6.0
Visual Studio: Microsoft Visual Studio Enterprise 2022 (64-bit) - Preview Version 17.8.0 Preview 4.0

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions