I have an routing error since we have migrating from .netCore 2.1 to 3.1.
Here are some explanations : In a web application, in the startup.cs, we have 2 routes like this :
endpoints.MapControllerRoute(
name: "MyCustomRoute1",
pattern: "MyPath/{slug}/m{id1}s{id2}", //MyPath/my-slug/m38s1
defaults: new { controller = "home", action = "Index" },
constraints: new { slug = "[a-z-]+", id1 = "[0-9]+", id2 = "[0-9]+" });
endpoints.MapControllerRoute(
name: "MyCustomRoute2",
pattern: "MyPath/{slug}/s{id1}", //MyPath/my-slug/s1
defaults: new { controller = "home", action = "Index" },
constraints: new { slug = "[a-z-]+", id1 = "[0-9]+" });
When I launch this URL https://localhost:44300/MyPath/my-slug/m38s1 I
have no error and MyCustomRoute1 is used.
When I launch this URL https://localhost:44300/MyPath/my-slug/s1, the route MyCustomRoute2 should be used. But I have this error :
ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
System.ReadOnlySpan<T>.Slice(int start, int length)
Microsoft.AspNetCore.Routing.RoutePatternMatcher.MatchComplexSegmentCore(RoutePatternPathSegment routeSegment, ReadOnlySpan<char> requestSegment, RouteValueDictionary values, int indexOfLastSegmentUsed)
Microsoft.AspNetCore.Routing.RoutePatternMatcher.MatchComplexSegment(RoutePatternPathSegment routeSegment, ReadOnlySpan<char> requestSegment, RouteValueDictionary values)
Microsoft.AspNetCore.Routing.Matching.DfaMatcher.ProcessComplexSegments(Endpoint endpoint, ValueTuple<RoutePatternPathSegment, int>[] complexSegments, string path, ReadOnlySpan<PathSegment> segments, RouteValueDictionary values)
Microsoft.AspNetCore.Routing.Matching.DfaMatcher.MatchAsync(HttpContext httpContext)
Microsoft.AspNetCore.Routing.Matching.DataSourceDependentMatcher.MatchAsync(HttpContext httpContext)
Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.Invoke(HttpContext httpContext)
Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
I think that the routing engine chose the wrong route (MyCustomRoute1 instead of MyCustomRoute2) and cannot create routeData
These configuration work fine on .netCore 2.1 but not in .netCore 3.1. I also try in .Net5 : this is the same problem.