sdk icon indicating copy to clipboard operation
sdk copied to clipboard

`dotnet format` does not respect interceptors for Request Delegate Generator

Open DeagleGross opened this issue 3 months ago • 3 comments

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.

DeagleGross avatar Oct 06 '25 16:10 DeagleGross

Same issue with configuration binder source generator.

jadu-1337 avatar Nov 20 '25 11:11 jadu-1337

@phil-allen-msft

agocke avatar Dec 03 '25 17:12 agocke

Suppressor support has merged into 10.0.2xx and we are taking it to tactics to backport to 10.0.1xx.

JoeRobich avatar Dec 11 '25 22:12 JoeRobich

Perhaps this is the duplicate for the other, similar issue?

phil-allen-msft avatar Dec 15 '25 19:12 phil-allen-msft