-
Notifications
You must be signed in to change notification settings - Fork 10.6k
RouteEndpoint metadata from convention builders are duplicated #34199
Copy link
Copy link
Closed
Labels
Priority:3Work that is nice to haveWork that is nice to havearea-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcarea-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesbugThis issue describes a behavior which is not expected - a bug.This issue describes a behavior which is not expected - a bug.feature-minimal-actionsController-like actions for endpoint routingController-like actions for endpoint routingfeature-routinginvestigate
Milestone
Metadata
Metadata
Assignees
Labels
Priority:3Work that is nice to haveWork that is nice to havearea-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcarea-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesbugThis issue describes a behavior which is not expected - a bug.This issue describes a behavior which is not expected - a bug.feature-minimal-actionsController-like actions for endpoint routingController-like actions for endpoint routingfeature-routinginvestigate
Type
Fields
Give feedbackNo fields configured for issues without a type.
Describe the bug
When inspecting endpoints with
EndpointDataSource, for example in anIApiDescriptionProvider, some of the metadata onRouteEndpointinstances is duplicated. As shown in the screenshot below, there are two duplicated HTTP method metadata items.Tracing through the code, this appears to be caused by a number of factors that together contribute to the routing endpoint conventions for an endpoint builder being run multiple times. The screenshot below shows the HTTP method metadata being added to the endpoint builder a second time.
The contributing factors to this issue appear to be:
CompositeEndpointDataSourceinstances created by the application:aspnetcore/src/Http/Routing/src/EndpointRoutingMiddleware.cs
Line 44 in 5577c0d
aspnetcore/src/Http/Routing/src/DependencyInjection/RoutingServiceCollectionExtensions.cs
Line 65 in 5577c0d
CompositeEndpointDataSourceenumerates theEndpointsproperty of each underlying endpoint data source once:aspnetcore/src/Http/Routing/src/CompositeEndpointDataSource.cs
Line 115 in 5577c0d
ModelEndpointDataSourcecallsBuild()on each convention builder each time theEndpointsproperty is accessedaspnetcore/src/Http/Routing/src/ModelEndpointDataSource.cs
Line 35 in 5577c0d
Build()runs the convention action(s):aspnetcore/src/Http/Routing/src/DefaultEndpointConventionBuilder.cs
Lines 30 to 33 in 5577c0d
aspnetcore/src/Http/Routing/src/Builder/RoutingEndpointConventionBuilderExtensions.cs
Lines 111 to 117 in 5577c0d
The net result is that every time the
Endpointsproperty of anModelEndpointDataSourceis accessed, the number ofMetadataitems on a route endpoint increases by the number of conventions configured.Below is an example of four duplicate metadata items in a sample application:
To Reproduce
To reproduce this issue, edit this test to have the following code:
Then debug the
JsonResult_Works()test with a breakpoint set here:aspnetcore/src/Mvc/Mvc.ApiExplorer/src/EndpointMetadataApiDescriptionProvider.cs
Line 59 in b9efadc
Inspecting
routeEndpoint.Metadatawith the debugger will show the duplicated metadata as shown in the preceding screenshots.Further technical details
6.0.0-preview.7.21357.16.0.100-preview.7.21357.57