Skip to content

.NET: Suppress IL2026/IL3050 trimming diagnostics in hosting projects#4586

Open
rogerbarreto wants to merge 2 commits intomicrosoft:mainfrom
rogerbarreto:address-format-issues
Open

.NET: Suppress IL2026/IL3050 trimming diagnostics in hosting projects#4586
rogerbarreto wants to merge 2 commits intomicrosoft:mainfrom
rogerbarreto:address-format-issues

Conversation

@rogerbarreto
Copy link
Member

Motivation and Context

Add NoWarn for IL2026 and IL3050 to the OpenAI and AGUI hosting projects only. These projects use ASP.NET Core endpoint routing APIs that trigger RequiresUnreferencedCode/RequiresDynamicCode attribute propagation, causing dotnet format to auto-add unwanted attributes. The suppression is scoped to these projects so the diagnostics remain active elsewhere.

image

Copilot AI review requested due to automatic review settings March 10, 2026 14:47
@rogerbarreto rogerbarreto self-assigned this Mar 10, 2026
@github-actions github-actions bot changed the title .Net: Suppress IL2026/IL3050 trimming diagnostics in hosting projects .NET: Suppress IL2026/IL3050 trimming diagnostics in hosting projects Mar 10, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR suppresses the IL2026 (RequiresUnreferencedCode) and IL3050 (RequiresDynamicCode) compiler diagnostics in the two hosting projects that use ASP.NET Core minimal API endpoint routing (MapPost, MapGet, etc.) with the Request Delegate Generator enabled. These diagnostics are otherwise propagated by dotnet format, causing unwanted attribute additions. The suppressions are narrowly scoped to only the affected projects.

Changes:

  • Add IL2026 and IL3050 to NoWarn in the OpenAI hosting project (alongside the existing MEAI001 suppression).
  • Add a new NoWarn line with IL2026 and IL3050 to the AGUI ASP.NET Core hosting project.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/Microsoft.Agents.AI.Hosting.OpenAI.csproj Appends IL2026 and IL3050 to the existing NoWarn list
dotnet/src/Microsoft.Agents.AI.Hosting.AGUI.AspNetCore/Microsoft.Agents.AI.Hosting.AGUI.AspNetCore.csproj Adds a new NoWarn property suppressing IL2026 and IL3050

@stephentoub
Copy link
Member

Wouldn't it be better to fix these and remain NativeAOT-friendly than to suppress the warnings?

@rogerbarreto
Copy link
Member Author

rogerbarreto commented Mar 10, 2026

Wouldn't it be better to fix these and remain NativeAOT-friendly than to suppress the warnings?

@stephentoub, as stated by @DeagleGross awhile ago.

"there is a bug in dotnet format where it does not respect IL2026 and IL3050 even when proper configuration was supplied to the csproj. Those warnings rise on the attempt to add endpoint handlers to the IEndpointRouteBuilder like app.MapGet("/", () => "hello world") in AOT scenarios where endpoint handler code has to be generated."

@stephentoub
Copy link
Member

stephentoub commented Mar 10, 2026

Wouldn't it be better to fix these and remain NativeAOT-friendly than to suppress the warnings?

@stephentoub, as stated by @DeagleGross awhile ago.

"there is a bug in dotnet format where it does not respect IL2026 and IL3050 even when proper configuration was supplied to the csproj. Those warnings rise on the attempt to add endpoint handlers to the IEndpointRouteBuilder like app.MapGet("/", () => "hello world") in AOT scenarios where endpoint handler code has to be generated."

Fixes for that were already merged. Does the repo just need a newer SDK?

Suppressing these for the whole project like this means we won't know if there are any other issues that creep in.

Copilot AI review requested due to automatic review settings March 10, 2026 15:39
Add #pragma warning disable/restore for IL2026 and IL3050 only around
the specific methods where dotnet format incorrectly adds
[RequiresUnreferencedCode] and [RequiresDynamicCode] attributes despite
proper interceptors configuration in the csproj.

See dotnet/sdk#51136

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.

@rogerbarreto
Copy link
Member Author

Suppressing these for the whole project like this means we won't know if there are any other issues that creep in.

@stephentoub, agree, updated to the specific methods, with the comment on the tracking issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants