From cde4acabc8242e262d1ce7bfdd15d33e14c9fffd Mon Sep 17 00:00:00 2001
From: Roger Barreto <19890735+rogerbarreto@users.noreply.github.com>
Date: Tue, 10 Mar 2026 15:41:31 +0000
Subject: [PATCH 1/2] Suppress IL2026/IL3050 with targeted pragmas on affected
methods
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 https://github.com/dotnet/sdk/issues/51136
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---
.../AGUIEndpointRouteBuilderExtensions.cs | 3 +++
.../EndpointRouteBuilderExtensions.ChatCompletions.cs | 3 +++
.../EndpointRouteBuilderExtensions.Conversations.cs | 3 +++
.../EndpointRouteBuilderExtensions.Responses.cs | 6 ++++++
4 files changed, 15 insertions(+)
diff --git a/dotnet/src/Microsoft.Agents.AI.Hosting.AGUI.AspNetCore/AGUIEndpointRouteBuilderExtensions.cs b/dotnet/src/Microsoft.Agents.AI.Hosting.AGUI.AspNetCore/AGUIEndpointRouteBuilderExtensions.cs
index e20d1ab448..e3109e6b8f 100644
--- a/dotnet/src/Microsoft.Agents.AI.Hosting.AGUI.AspNetCore/AGUIEndpointRouteBuilderExtensions.cs
+++ b/dotnet/src/Microsoft.Agents.AI.Hosting.AGUI.AspNetCore/AGUIEndpointRouteBuilderExtensions.cs
@@ -28,6 +28,8 @@ public static class AGUIEndpointRouteBuilderExtensions
/// The URL pattern for the endpoint.
/// The agent instance.
/// An for the mapped endpoint.
+ // Workaround: dotnet format does not respect IL2026/IL3050 with interceptors configuration. See https://github.com/dotnet/sdk/issues/51136
+#pragma warning disable IL2026, IL3050
public static IEndpointConventionBuilder MapAGUI(
this IEndpointRouteBuilder endpoints,
[StringSyntax("route")] string pattern,
@@ -80,4 +82,5 @@ public static IEndpointConventionBuilder MapAGUI(
return new AGUIServerSentEventsResult(events, sseLogger);
});
}
+#pragma warning restore IL2026, IL3050
}
diff --git a/dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/EndpointRouteBuilderExtensions.ChatCompletions.cs b/dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/EndpointRouteBuilderExtensions.ChatCompletions.cs
index 92c817b124..0854fc7e01 100644
--- a/dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/EndpointRouteBuilderExtensions.ChatCompletions.cs
+++ b/dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/EndpointRouteBuilderExtensions.ChatCompletions.cs
@@ -49,6 +49,8 @@ public static IEndpointConventionBuilder MapOpenAIChatCompletions(this IEndpoint
/// The to add the OpenAI ChatCompletions endpoints to.
/// The instance to map the OpenAI ChatCompletions endpoints for.
/// Custom route path for the chat completions endpoint.
+ // Workaround: dotnet format does not respect IL2026/IL3050 with interceptors configuration. See https://github.com/dotnet/sdk/issues/51136
+#pragma warning disable IL2026, IL3050
public static IEndpointConventionBuilder MapOpenAIChatCompletions(
this IEndpointRouteBuilder endpoints,
AIAgent agent,
@@ -69,4 +71,5 @@ public static IEndpointConventionBuilder MapOpenAIChatCompletions(
return group;
}
+#pragma warning restore IL2026, IL3050
}
diff --git a/dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/EndpointRouteBuilderExtensions.Conversations.cs b/dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/EndpointRouteBuilderExtensions.Conversations.cs
index 0c4af2cfb5..12c71907bc 100644
--- a/dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/EndpointRouteBuilderExtensions.Conversations.cs
+++ b/dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/EndpointRouteBuilderExtensions.Conversations.cs
@@ -17,6 +17,8 @@ public static partial class MicrosoftAgentAIHostingOpenAIEndpointRouteBuilderExt
/// Maps OpenAI Conversations API endpoints to the specified .
///
/// The to add the OpenAI Conversations endpoints to.
+ // Workaround: dotnet format does not respect IL2026/IL3050 with interceptors configuration. See https://github.com/dotnet/sdk/issues/51136
+#pragma warning disable IL2026, IL3050
public static IEndpointConventionBuilder MapOpenAIConversations(this IEndpointRouteBuilder endpoints)
{
ArgumentNullException.ThrowIfNull(endpoints);
@@ -70,4 +72,5 @@ public static IEndpointConventionBuilder MapOpenAIConversations(this IEndpointRo
return group;
}
+#pragma warning restore IL2026, IL3050
}
diff --git a/dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/EndpointRouteBuilderExtensions.Responses.cs b/dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/EndpointRouteBuilderExtensions.Responses.cs
index ae96636f16..cc3ad1661e 100644
--- a/dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/EndpointRouteBuilderExtensions.Responses.cs
+++ b/dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/EndpointRouteBuilderExtensions.Responses.cs
@@ -55,6 +55,8 @@ public static IEndpointConventionBuilder MapOpenAIResponses(this IEndpointRouteB
/// The to add the OpenAI Responses endpoints to.
/// The instance to map the OpenAI Responses endpoints for.
/// Custom route path for the responses endpoint.
+ // Workaround: dotnet format does not respect IL2026/IL3050 with interceptors configuration. See https://github.com/dotnet/sdk/issues/51136
+#pragma warning disable IL2026, IL3050
public static IEndpointConventionBuilder MapOpenAIResponses(
this IEndpointRouteBuilder endpoints,
AIAgent agent,
@@ -105,6 +107,7 @@ public static IEndpointConventionBuilder MapOpenAIResponses(
return group;
}
+#pragma warning restore IL2026, IL3050
///
/// Maps OpenAI Responses API endpoints to the specified .
@@ -118,6 +121,8 @@ public static IEndpointConventionBuilder MapOpenAIResponses(this IEndpointRouteB
///
/// The to add the OpenAI Responses endpoints to.
/// Custom route path for the responses endpoint.
+ // Workaround: dotnet format does not respect IL2026/IL3050 with interceptors configuration. See https://github.com/dotnet/sdk/issues/51136
+#pragma warning disable IL2026, IL3050
public static IEndpointConventionBuilder MapOpenAIResponses(
this IEndpointRouteBuilder endpoints,
[StringSyntax("Route")] string? responsesPath)
@@ -158,6 +163,7 @@ public static IEndpointConventionBuilder MapOpenAIResponses(
return group;
}
+#pragma warning restore IL2026, IL3050
private static void ValidateAgentName([NotNull] string agentName)
{
From efdb7857e9a3ccebd356643d5a41d50fe4a61c87 Mon Sep 17 00:00:00 2001
From: Roger Barreto <19890735+rogerbarreto@users.noreply.github.com>
Date: Wed, 11 Mar 2026 09:00:29 +0000
Subject: [PATCH 2/2] Upgrade to .NET SDK 10.0.200 and remove IL2026/IL3050
workarounds
Bump global.json to SDK 10.0.200 which fixes the dotnet format bug
that incorrectly added [RequiresUnreferencedCode] and
[RequiresDynamicCode] attributes (https://github.com/dotnet/sdk/issues/51136).
Remove all #pragma warning disable IL2026/IL3050 workarounds from
source files and the --exclude-diagnostics flag from the CI format
workflow.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---
.github/workflows/dotnet-format.yml | 3 +--
dotnet/global.json | 2 +-
.../AGUIEndpointRouteBuilderExtensions.cs | 3 ---
.../EndpointRouteBuilderExtensions.ChatCompletions.cs | 3 ---
.../EndpointRouteBuilderExtensions.Conversations.cs | 3 ---
.../EndpointRouteBuilderExtensions.Responses.cs | 6 ------
6 files changed, 2 insertions(+), 18 deletions(-)
diff --git a/.github/workflows/dotnet-format.yml b/.github/workflows/dotnet-format.yml
index 8d7c9febb7..8bdaeba8a3 100644
--- a/.github/workflows/dotnet-format.yml
+++ b/.github/workflows/dotnet-format.yml
@@ -86,11 +86,10 @@ jobs:
run: docker pull mcr.microsoft.com/dotnet/sdk:${{ matrix.dotnet }}
# This step will run dotnet format on each of the unique csproj files and fail if any changes are made
- # exclude-diagnostics should be removed after fixes for IL2026 and IL3050 are out: https://github.com/dotnet/sdk/issues/51136
- name: Run dotnet format
if: steps.find-csproj.outputs.csproj_files != ''
run: |
for csproj in ${{ steps.find-csproj.outputs.csproj_files }}; do
echo "Running dotnet format on $csproj"
- docker run --rm -v $(pwd):/app -w /app mcr.microsoft.com/dotnet/sdk:${{ matrix.dotnet }} /bin/sh -c "dotnet format $csproj --verify-no-changes --verbosity diagnostic --exclude-diagnostics IL2026 IL3050"
+ docker run --rm -v $(pwd):/app -w /app mcr.microsoft.com/dotnet/sdk:${{ matrix.dotnet }} /bin/sh -c "dotnet format $csproj --verify-no-changes --verbosity diagnostic"
done
diff --git a/dotnet/global.json b/dotnet/global.json
index 482aa6b8d3..42bb8863a3 100644
--- a/dotnet/global.json
+++ b/dotnet/global.json
@@ -1,6 +1,6 @@
{
"sdk": {
- "version": "10.0.100",
+ "version": "10.0.200",
"rollForward": "minor",
"allowPrerelease": false
},
diff --git a/dotnet/src/Microsoft.Agents.AI.Hosting.AGUI.AspNetCore/AGUIEndpointRouteBuilderExtensions.cs b/dotnet/src/Microsoft.Agents.AI.Hosting.AGUI.AspNetCore/AGUIEndpointRouteBuilderExtensions.cs
index e3109e6b8f..e20d1ab448 100644
--- a/dotnet/src/Microsoft.Agents.AI.Hosting.AGUI.AspNetCore/AGUIEndpointRouteBuilderExtensions.cs
+++ b/dotnet/src/Microsoft.Agents.AI.Hosting.AGUI.AspNetCore/AGUIEndpointRouteBuilderExtensions.cs
@@ -28,8 +28,6 @@ public static class AGUIEndpointRouteBuilderExtensions
/// The URL pattern for the endpoint.
/// The agent instance.
/// An for the mapped endpoint.
- // Workaround: dotnet format does not respect IL2026/IL3050 with interceptors configuration. See https://github.com/dotnet/sdk/issues/51136
-#pragma warning disable IL2026, IL3050
public static IEndpointConventionBuilder MapAGUI(
this IEndpointRouteBuilder endpoints,
[StringSyntax("route")] string pattern,
@@ -82,5 +80,4 @@ public static IEndpointConventionBuilder MapAGUI(
return new AGUIServerSentEventsResult(events, sseLogger);
});
}
-#pragma warning restore IL2026, IL3050
}
diff --git a/dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/EndpointRouteBuilderExtensions.ChatCompletions.cs b/dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/EndpointRouteBuilderExtensions.ChatCompletions.cs
index 0854fc7e01..92c817b124 100644
--- a/dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/EndpointRouteBuilderExtensions.ChatCompletions.cs
+++ b/dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/EndpointRouteBuilderExtensions.ChatCompletions.cs
@@ -49,8 +49,6 @@ public static IEndpointConventionBuilder MapOpenAIChatCompletions(this IEndpoint
/// The to add the OpenAI ChatCompletions endpoints to.
/// The instance to map the OpenAI ChatCompletions endpoints for.
/// Custom route path for the chat completions endpoint.
- // Workaround: dotnet format does not respect IL2026/IL3050 with interceptors configuration. See https://github.com/dotnet/sdk/issues/51136
-#pragma warning disable IL2026, IL3050
public static IEndpointConventionBuilder MapOpenAIChatCompletions(
this IEndpointRouteBuilder endpoints,
AIAgent agent,
@@ -71,5 +69,4 @@ public static IEndpointConventionBuilder MapOpenAIChatCompletions(
return group;
}
-#pragma warning restore IL2026, IL3050
}
diff --git a/dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/EndpointRouteBuilderExtensions.Conversations.cs b/dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/EndpointRouteBuilderExtensions.Conversations.cs
index 12c71907bc..0c4af2cfb5 100644
--- a/dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/EndpointRouteBuilderExtensions.Conversations.cs
+++ b/dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/EndpointRouteBuilderExtensions.Conversations.cs
@@ -17,8 +17,6 @@ public static partial class MicrosoftAgentAIHostingOpenAIEndpointRouteBuilderExt
/// Maps OpenAI Conversations API endpoints to the specified .
///
/// The to add the OpenAI Conversations endpoints to.
- // Workaround: dotnet format does not respect IL2026/IL3050 with interceptors configuration. See https://github.com/dotnet/sdk/issues/51136
-#pragma warning disable IL2026, IL3050
public static IEndpointConventionBuilder MapOpenAIConversations(this IEndpointRouteBuilder endpoints)
{
ArgumentNullException.ThrowIfNull(endpoints);
@@ -72,5 +70,4 @@ public static IEndpointConventionBuilder MapOpenAIConversations(this IEndpointRo
return group;
}
-#pragma warning restore IL2026, IL3050
}
diff --git a/dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/EndpointRouteBuilderExtensions.Responses.cs b/dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/EndpointRouteBuilderExtensions.Responses.cs
index cc3ad1661e..ae96636f16 100644
--- a/dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/EndpointRouteBuilderExtensions.Responses.cs
+++ b/dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/EndpointRouteBuilderExtensions.Responses.cs
@@ -55,8 +55,6 @@ public static IEndpointConventionBuilder MapOpenAIResponses(this IEndpointRouteB
/// The to add the OpenAI Responses endpoints to.
/// The instance to map the OpenAI Responses endpoints for.
/// Custom route path for the responses endpoint.
- // Workaround: dotnet format does not respect IL2026/IL3050 with interceptors configuration. See https://github.com/dotnet/sdk/issues/51136
-#pragma warning disable IL2026, IL3050
public static IEndpointConventionBuilder MapOpenAIResponses(
this IEndpointRouteBuilder endpoints,
AIAgent agent,
@@ -107,7 +105,6 @@ public static IEndpointConventionBuilder MapOpenAIResponses(
return group;
}
-#pragma warning restore IL2026, IL3050
///
/// Maps OpenAI Responses API endpoints to the specified .
@@ -121,8 +118,6 @@ public static IEndpointConventionBuilder MapOpenAIResponses(this IEndpointRouteB
///
/// The to add the OpenAI Responses endpoints to.
/// Custom route path for the responses endpoint.
- // Workaround: dotnet format does not respect IL2026/IL3050 with interceptors configuration. See https://github.com/dotnet/sdk/issues/51136
-#pragma warning disable IL2026, IL3050
public static IEndpointConventionBuilder MapOpenAIResponses(
this IEndpointRouteBuilder endpoints,
[StringSyntax("Route")] string? responsesPath)
@@ -163,7 +158,6 @@ public static IEndpointConventionBuilder MapOpenAIResponses(
return group;
}
-#pragma warning restore IL2026, IL3050
private static void ValidateAgentName([NotNull] string agentName)
{