dotnet / dotnet/sdk

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

Open
#51,136 5 comments 4 reactions 1 assignee Claimed by @JoeRobich View on GitHub
Area-Format untriaged
Dominant language
C#
Stars
3.2k
Forks
1.3k
PR merge metrics
PR metrics pending

Description

### 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:
```xml
$(InterceptorsNamespaces);Microsoft.AspNetCore.Http.Generated
true
```

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:
```csharp
[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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.