Skip to content

RequestDelegateGenerator fails to detect route pattern that uses a constant for its value #48307

Closed
@martincostello

Description

@martincostello

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

If a Map*() method references a constant for the route pattern, an RDG001 error is emitted for the endpoint and no code is generated.

Unable to statically resolve route pattern 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/aot-known-issues	

I checked the known issues and this specific problem doesn't appear to be listed.

For example, this code references constants for the paths so that they can be reused with configuring OAuth:

private const string DeniedPath = "/denied";
private const string SignInPath = "/sign-in";
private const string SignOutPath = "/sign-out";

public static IEndpointRouteBuilder MapAuthenticationRoutes(this IEndpointRouteBuilder builder)
{
    builder.MapGet(DeniedPath, () => Results.Redirect(RootPath + "?denied=true"))
           .ExcludeFromDescription();

    builder.MapGet(SignOutPath, () => Results.Redirect(RootPath))
           .ExcludeFromDescription();

    builder.MapPost(SignInPath, () => Results.Challenge(new() { RedirectUri = RootPath }, new[] { GitHubAuthenticationDefaults.AuthenticationScheme }))
           .ExcludeFromDescription();

    builder.MapPost(SignOutPath, () => Results.SignOut(new() { RedirectUri = RootPath }, new[] { CookieAuthenticationDefaults.AuthenticationScheme }))
           .ExcludeFromDescription()
           .RequireAuthorization();

    return builder;
}

Expected Behavior

The source generator acquires the static value of the constant to obtain the route template.

Steps To Reproduce

  1. Clone martincostello/dotnet-minimal-api-integration-testing@774c5a4
  2. Add the following to src/TodoApp/TodoApp.csproj: <EnableRequestDelegateGenerator>true</EnableRequestDelegateGenerator>
  3. Build the TodoApp project

Exceptions (if any)

No response

.NET Version

8.0.100-preview.4.23260.5

Anything else?

No response

Metadata

Metadata

Assignees

Labels

NativeAOTarea-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-rdg

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions