Skip to content

Multiple MapDynamicControllerRoute: Using ExpandEndpoint requires that the replaced endpoint have a unique priority. #28516

Closed
@Tripplefix

Description

@Tripplefix

Description of the bug

If you try to map multiple dynamic controller routes on startup of an asp.Net core project, an "InvalidOperationException" will be thrown. I have discovered this behaviour when I was working on a larger website with multiple projects where two different projects need to register their own DynamicRouteValueTransformer. In the example code below I have registered the two Transformers as such:

endpoints.MapDynamicControllerRoute<Test1RouteTransformer>("{SeName}");
endpoints.MapDynamicControllerRoute<Test2RouteTransformer>("{SeName}");

... and then got the same exception. Remove any of the two lines and the routing works (for the one that remains).

To Reproduce

Clone this repo: https://github.com/Tripplefix/MapDynamicControllerRouteTest
Then start the webserver and open https://localhost:5001/test-foo and https://localhost:5001/test-bar

Exceptions

The two URLs mentioned before throw two different but seemingly related exceptions:

InvalidOperationException: Using ExpandEndpoint requires that the replaced endpoint have a unique priority. The following endpoints were found with the same priority: {SeName} {SeName}
Microsoft.AspNetCore.Routing.Matching.CandidateSet.ValidateUniqueScore(int index)
Microsoft.AspNetCore.Routing.Matching.CandidateSet.ExpandEndpoint(int index, IReadOnlyList<Endpoint> endpoints, IComparer<Endpoint> comparer)
Microsoft.AspNetCore.Mvc.Routing.DynamicControllerEndpointMatcherPolicy.ApplyAsync(HttpContext httpContext, CandidateSet candidates)
Microsoft.AspNetCore.Routing.Matching.DfaMatcher.SelectEndpointWithPoliciesAsync(HttpContext httpContext, IEndpointSelectorPolicy[] policies, CandidateSet candidateSet)
Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.<Invoke>g__AwaitMatch|8_1(EndpointRoutingMiddleware middleware, HttpContext httpContext, Task matchTask)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

image

NullReferenceException: Object reference not set to an instance of an object.
Microsoft.AspNetCore.Routing.Matching.CandidateSet+<>c.<ValidateUniqueScore>b__15_0(Endpoint e)
System.Linq.Enumerable+SelectListIterator<TSource, TResult>.MoveNext()
string.Join(string separator, IEnumerable<string> values)
Microsoft.AspNetCore.Routing.Matching.CandidateSet.ValidateUniqueScore(int index)
Microsoft.AspNetCore.Routing.Matching.CandidateSet.ExpandEndpoint(int index, IReadOnlyList<Endpoint> endpoints, IComparer<Endpoint> comparer)
Microsoft.AspNetCore.Mvc.Routing.DynamicControllerEndpointMatcherPolicy.ApplyAsync(HttpContext httpContext, CandidateSet candidates)
Microsoft.AspNetCore.Routing.Matching.DfaMatcher.SelectEndpointWithPoliciesAsync(HttpContext httpContext, IEndpointSelectorPolicy[] policies, CandidateSet candidateSet)
Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.<Invoke>g__AwaitMatch|8_1(EndpointRoutingMiddleware middleware, HttpContext httpContext, Task matchTask)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

image

Expected behaviour

It should be possible to map/register multiple dynamic controller routes.

Further technical details

The output of dotnet --info

C:\Entwicklung\MapDynamicControllerRouteTest>dotnet --info
.NET Core SDK (reflecting any global.json):
 Version:   3.1.404
 Commit:    470f6754b3

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19041
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\3.1.404\

Host (useful for support):
  Version: 5.0.0
  Commit:  cf258a14b7

.NET SDKs installed:
  3.1.404 [C:\Program Files\dotnet\sdk]
  5.0.100 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 3.1.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.1.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

I am working with Rider 2020.2.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesbugThis issue describes a behavior which is not expected - a bug.feature-routinginvestigate

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions