-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Closed
Labels
NativeAOTarea-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-rdg
Milestone
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
The Request Delegate Generator does not properly handle optional delegate parameters annotated with [FromQuery], as it does not convert from a string to the expected type.
Removing the attribute removes the error.
In the generated code, the last line of code produces the error.
var test_raw = httpContext.Request.Query["test"];
var test_temp = test_raw.Count > 0 ? (string?)test_raw : 10;Without the attribute, the RDG generates this code
var test2_raw = test2_RouteOrQueryResolver(httpContext);
var test2_temp = test2_raw.Count > 0 ? (string?)test2_raw : null;In both cases, the resulting parameter appears to be properly defaulted to the value prescribed assuming the temp value is null or empty.
Expected Behavior
A parameter should be allowed to be annotated with [FromQuery] to be explicit around resolution of the parameter. The parameter should also be allowed to be optional with a default.
Steps To Reproduce
https://github.com/ryanseipp/dotnet-aot-from-query
See Program.cs line 28
Exceptions (if any)
/home/user/Code/dotnet-aot-from-query/DotnetAotFromQuery/Microsoft.AspNetCore.Http.RequestDelegateGenerator/Microsoft.AspNetCore.Http.RequestDelegateGenerator.RequestDelegateGenerator/GeneratedRouteBuilderExtensions.g.cs(209,37): error CS0173: Type of conditional expression cannot be determined because there is no implicit conversion between 'string' and 'int' [/home/user/Code/dotnet-aot-from-query/DotnetAotFromQuery/DotnetAotFromQuery.csproj]
.NET Version
8.0.100
Anything else?
No response
Metadata
Metadata
Assignees
Labels
NativeAOTarea-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-rdg