.NET: Suppress IL2026/IL3050 trimming diagnostics in hosting projects#4586
.NET: Suppress IL2026/IL3050 trimming diagnostics in hosting projects#4586rogerbarreto wants to merge 2 commits intomicrosoft:mainfrom
Conversation
There was a problem hiding this comment.
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
IL2026andIL3050toNoWarnin the OpenAI hosting project (alongside the existingMEAI001suppression). - Add a new
NoWarnline withIL2026andIL3050to 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 |
|
Wouldn't it be better to fix these and remain NativeAOT-friendly than to suppress the warnings? |
@stephentoub, as stated by @DeagleGross awhile ago.
|
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. |
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>
c2429d7 to
cde4aca
Compare
@stephentoub, agree, updated to the specific methods, with the comment on the tracking issue. |
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.