Skip to content

dotnet format does not respect interceptors for Request Delegate Generator #51136

@DeagleGross

Description

@DeagleGross

Describe the bug

I have an aspnetcore code which registers new endpoint handlers via MapGet or MapPost with enabled Request Delegate Generator (RDG). To support AOT scenarios, I've enabled:

    <InterceptorsNamespaces>$(InterceptorsNamespaces);Microsoft.AspNetCore.Http.Generated</InterceptorsNamespaces>
    <EnableRequestDelegateGenerator>true</EnableRequestDelegateGenerator>

However, dotnet format (which is enabled in the CI) blocks the PR from merging reporting

/app/dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/EndpointRouteBuilderExtensions.cs(84,9): error IL2026: Using member 'Microsoft.AspNetCore.Builder.EndpointRouteBuilderExtensions.MapGet(IEndpointRouteBuilder, String, Delegate)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. This API may perform reflection on the supplied delegate and its parameters. These types may be trimmed if not directly referenced. [/app/dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/Microsoft.Agents.AI.Hosting.OpenAI.csproj]

To Reproduce

  1. git clone https://github.com/microsoft/agent-framework.git
  2. cd agent-framework
  3. git checkout -b dmkorolev/openai-responses origin/dmkorolev/openai-responses (or main if custom branch does not exist)
  4. dotnet format .\dotnet\src\Microsoft.Agents.AI.Hosting.OpenAI\Microsoft.Agents.AI.Hosting.OpenAI.csproj

It will add:

 [RequiresDynamicCode("Calls Microsoft.AspNetCore.Builder.EndpointRouteBuilderExtensions.MapPost(String, Delegate)")]
 [RequiresUnreferencedCode("Calls Microsoft.AspNetCore.Builder.EndpointRouteBuilderExtensions.MapPost(String, Delegate)")]

however it should not, because the RDG interceptor logic is replacing the calls to MapGet and MapPost

Expected Behavior

dotnet format should not report IL2026 and IL3050 because AOT is being correctly supported via RDG.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions