Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.0-preview.5] Endpoint with nullable parameter no longer generates code with Request Delegate Generator #55840

Closed
1 task done
martincostello opened this issue May 22, 2024 · 3 comments · Fixed by #56332
Closed
1 task done
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc feature-rdg NativeAOT

Comments

@martincostello
Copy link
Member

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Using version 9.0.100-preview.5.24272.3 of the .NET SDK from daily builds, an endpoint associated with a method that has a string[]? parameter is no longer having an endpoint generated an produces a RDG003 warning.

Error: /home/runner/work/adventofcode/adventofcode/src/AdventOfCode.Site/Program.cs(135,1): error RDG003: Unable to statically resolve parameter named 'arguments' for endpoint. Compile-time endpoint generation will skip this endpoint and the endpoint will be generated at runtime. For more information, please see https://aka.ms/aspnet/rdg-known-issues (https://learn.microsoft.com/aspnet/core/fundamentals/aot/request-delegate-generator/diagnostics/RDG003) [/home/runner/work/adventofcode/adventofcode/src/AdventOfCode.Site/AdventOfCode.Site.csproj]

The error is not generated with .NET 8 or .NET 9 preview 4.

The signature of the endpoint is the following (code):

internal static async Task<IResult> SolvePuzzleAsync(
    int year,
    int day,
    HttpRequest request,
    [FromForm] string[]? arguments,
    IFormFile? resource,
    PuzzleFactory factory,
    TimeProvider timeProvider,
    ILogger<Puzzle> logger,
    CancellationToken cancellationToken)

Expected Behavior

Request Delegate Generator successfully generates code for this endpoint.

Steps To Reproduce

  1. Clone martincostello/adventofcode@fe22226#diff-f905acb7a057826fd183f2558445347c59e1cf0304dc0499d9f5e0ae4a523ebe
  2. Run build.ps1 in the root of the repository.

Exceptions (if any)

No response

.NET Version

9.0.100-preview.5.24272.3

Anything else?

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc label May 22, 2024
@martincostello
Copy link
Member Author

Looks like this was broken by #55465.

Specifically, this code addition:

// Complex form binding is only supported in RDF because it uses shared source with Blazor that requires dynamic analysis
// and codegen. Emit a diagnostic when these are encountered to avoid producing buggy code.
else if (!(SymbolEqualityComparer.Default.Equals(Type, wellKnownTypes.Get(WellKnownType.Microsoft_Extensions_Primitives_StringValues))
|| Type.SpecialType == SpecialType.System_String
|| TryGetParsability(Type, wellKnownTypes, out var _)
|| (IsArray && TryGetParsability(ElementType, wellKnownTypes, out var _))))
{
var location = endpoint.Operation.Syntax.GetLocation();
endpoint.Diagnostics.Add(Diagnostic.Create(DiagnosticDescriptors.UnableToResolveParameterDescriptor, location, symbol.Name));
}

@captainsafia
Copy link
Member

@martincostello Thanks for reporting this bug and apologies for the delay as I work through my backlog here! 😅

I believe the reason this is happening is because the target type is a string[] in particular. The condition that you referenced above needs an additional (IsArray && ElementType.SpecialType == SpecialType.System_String) check since we don't don't generate a parsability method for string types out of TryGetParsability.

PR incoming....

@martincostello
Copy link
Member Author

No problem - I did take a look at fixing it myself, but I wasn't sure if it was intentional or not so noped out of it 😅

Glad it's a quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc feature-rdg NativeAOT
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants