You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm experiencing an issue where ApiVersionMatcherPolicy invalidates a valid candidate, from what looks to be an attempt to optimize performance.
The setup is quite cumbersome, but I managed to setup a minimal solution to verify it (See below).
The use case is when I have a plain old WebAPI without any versioning and I have two endpoints with the same route. Furthermore I need to have a dynamic route, to even hit this code in the ApiVersionMatcherPolicy.
When I try to call ny POST endpoint, it returns 404, because it have been invalidated by ApiVersionMatcherPolicy that finds the GET endpoint as the bestMatch. This is a problem because the ApiVersionMatcherPolicy.Order is hardcoded to be lower than HttpMethodMatcherPolicy.Order.
Furtheremore I have a single file with two classes
usingSystem.Net.Mime;usingMicrosoft.AspNetCore.Mvc;usingMicrosoft.AspNetCore.Mvc.Routing;namespaceWebApplication5;publicclassMyDynamicControllerRoute:DynamicRouteValueTransformer{publicoverrideValueTask<RouteValueDictionary>TransformAsync(HttpContexthttpContext,RouteValueDictionaryvalues){returnValueTask.FromResult(values);}}[ApiController][Route("api/")]publicclassShowBugController:Controller{[HttpPost("test")][ProducesResponseType(StatusCodes.Status200OK)][Consumes(MediaTypeNames.Application.Json)]// This is important because it leads to a lower (better) score when the request enter the ApiVersionMatcherPolicy, even when requested with http GETpublicIActionResultMyPost(){returnOk("OK POST");}[HttpGet("test")][ProducesResponseType(StatusCodes.Status200OK)]publicIActionResultMyGet(){returnOk("OK GET");}}
Exceptions (if any)
No response
.NET Version
8.0.303
Anything else?
No response
The text was updated successfully, but these errors were encountered:
Is there an existing issue for this?
Describe the bug
I'm experiencing an issue where
ApiVersionMatcherPolicy
invalidates a valid candidate, from what looks to be an attempt to optimize performance.The setup is quite cumbersome, but I managed to setup a minimal solution to verify it (See below).
The use case is when I have a plain old WebAPI without any versioning and I have two endpoints with the same route. Furthermore I need to have a dynamic route, to even hit this code in the
ApiVersionMatcherPolicy
.When I try to call ny POST endpoint, it returns 404, because it have been invalidated by
ApiVersionMatcherPolicy
that finds the GET endpoint as thebestMatch
. This is a problem because theApiVersionMatcherPolicy.Order
is hardcoded to be lower thanHttpMethodMatcherPolicy.Order
.The issue is originally reported in Umbraco here: umbraco/Umbraco-CMS#16434
Expected Behavior
My GET endpoint is hit, like if
ApiVersionMatcherPolicy
is removed from the service collection.Steps To Reproduce
I have setup a minimal setup, that shows the issue.
https://github.com/bergmania/DemoIssueWithAPIVersioning
On a new MVC project, I added a dependency
I added the following in
program.cs
Before
var app = builder.Build();
and the following afterwardsFurtheremore I have a single file with two classes
Exceptions (if any)
No response
.NET Version
8.0.303
Anything else?
No response
The text was updated successfully, but these errors were encountered: