Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 task done
mikekistler opened this issue Dec 31, 2024 · 2 comments
Open
1 task done
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates

Comments

@mikekistler
Copy link
Contributor

mikekistler commented Dec 31, 2024

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

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Dec 31, 2024
@mikekistler mikekistler added the area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc label Dec 31, 2024
@davidfowl
Copy link
Member

This doesn’t look like a bug, those names are unique identifiers.

@mikekistler
Copy link
Contributor Author

I know the endpoint name is used in the OpenAPI document generation as the operationId, and this must be unique within an OpenAPI document. But with API versioning the OpenAPI document is split by version, so all v1 APIs go in one document and all v2 APIs go in a separate document.

How else is this name used that requires it to be unique "globally"?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates
Projects
None yet
Development

No branches or pull requests

2 participants