Skip to content

Runtime exception for endpoints in different API versions with the same endpoint name #59669

Closed as not planned
@mikekistler

Description

@mikekistler

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

In a Minimal API application using the Asp.Versioning package to implement API versioning, the runtime throws an exception if two endpoints in different API versions have the same endpoint name. The exception thrown is:

System.InvalidOperationException: Duplicate endpoint name 'Hello' found on 'HTTP: GET /hello' and 'HTTP: GET /hello'. Endpoint names must be globally unique.
   at Microsoft.AspNetCore.Routing.Matching.DataSourceDependentMatcher.CreateMatcher(IReadOnlyList`1 endpoints)
   at Microsoft.AspNetCore.Routing.DataSourceDependentCache`1.Initialize()
   at System.Threading.LazyInitializer.EnsureInitializedCore[T](T& target, Boolean& initialized, Object& syncLock, Func`1 valueFactory)
   at Microsoft.AspNetCore.Routing.Matching.DataSourceDependentMatcher..ctor(EndpointDataSource dataSource, Lifetime lifetime, Func`1 matcherBuilderFactory)
   at Microsoft.AspNetCore.Routing.Matching.DfaMatcherFactory.CreateMatcher(EndpointDataSource dataSource)
   at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.InitializeCoreAsync()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.<Invoke>g__AwaitMatcher|10_0(EndpointRoutingMiddleware middleware, HttpContext httpContext, Task`1 matcherTask)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)

Expected Behavior

I think that endpoint names should only be required to be unique within an API version.

Steps To Reproduce

This repo contains a branch that illustrates the issue.

Exceptions (if any)

See above.

.NET Version

9.0.100

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcarea-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templates

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions