From 4038d80409a5781ab8a3f32e8c90188a0396a9f6 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Tue, 19 May 2026 02:37:17 +0000
Subject: [PATCH 1/8] Enable trim and AOT analyzers in listed tests
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/5977beb1-58f4-4a75-9a1c-02ff1bb17294
Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
---
...Microsoft.Extensions.Configuration.CommandLine.Tests.csproj | 3 ---
.../tests/Microsoft.Extensions.Configuration.Ini.Tests.csproj | 3 ---
.../tests/Microsoft.Extensions.Configuration.Json.Tests.csproj | 3 ---
.../tests/Microsoft.Extensions.Configuration.Tests.csproj | 3 ---
...ensions.DependencyInjection.ExternalContainers.Tests.csproj | 2 --
.../Microsoft.Extensions.HostFactoryResolver.Tests.csproj | 2 --
.../tests/System.DirectoryServices.Tests.csproj | 2 --
.../System.IO.Packaging/tests/System.IO.Packaging.Tests.csproj | 2 --
.../System.Management/tests/System.Management.Tests.csproj | 3 ---
.../UnitTests/System.Net.Http.WinHttpHandler.Unit.Tests.csproj | 2 --
.../tests/Functional/System.Net.Mail.Functional.Tests.csproj | 2 --
.../FunctionalTests/System.Net.Quic.Functional.Tests.csproj | 2 --
.../tests/FunctionalTests/System.Net.Security.Tests.csproj | 2 --
.../System.Net.WebProxy/tests/System.Net.WebProxy.Tests.csproj | 2 --
.../tests/System.Net.WebSockets.Client.Tests.csproj | 2 --
.../ComInterfaceGenerator.Unit.Tests.csproj | 2 --
.../System.Runtime.InteropServices.ComDisabled.Tests.csproj | 2 --
.../tests/System.Runtime.Serialization.Primitives.Tests.csproj | 3 ---
.../tests/System.Buffers.Tests/System.Buffers.Tests.csproj | 2 --
.../CoreCLR/System.Reflection.CoreCLR.Tests.csproj | 2 --
...tem.Runtime.InteropServices.RuntimeInformation.Tests.csproj | 2 --
.../System.Runtime.ReflectionInvokeEmit.Tests.csproj | 2 --
.../System.Runtime.ReflectionInvokeInterpreted.Tests.csproj | 2 --
.../System.Threading.Tasks.Extensions.Tests.csproj | 2 --
.../tests/System.Security.Cryptography.Pkcs.Tests.csproj | 2 --
...tem.Text.Json.SourceGeneration.Roslyn3.11.Unit.Tests.csproj | 2 --
...stem.Text.Json.SourceGeneration.Roslyn4.4.Unit.Tests.csproj | 2 --
.../tests/System.Threading.RateLimiting.Tests.csproj | 2 --
28 files changed, 62 deletions(-)
diff --git a/src/libraries/Microsoft.Extensions.Configuration.CommandLine/tests/Microsoft.Extensions.Configuration.CommandLine.Tests.csproj b/src/libraries/Microsoft.Extensions.Configuration.CommandLine/tests/Microsoft.Extensions.Configuration.CommandLine.Tests.csproj
index 69800a8c2857f6..c50143436bfaf4 100644
--- a/src/libraries/Microsoft.Extensions.Configuration.CommandLine/tests/Microsoft.Extensions.Configuration.CommandLine.Tests.csproj
+++ b/src/libraries/Microsoft.Extensions.Configuration.CommandLine/tests/Microsoft.Extensions.Configuration.CommandLine.Tests.csproj
@@ -3,9 +3,6 @@
$(NetCoreAppCurrent);$(NetFrameworkCurrent)
true
-
- false
- false
diff --git a/src/libraries/Microsoft.Extensions.Configuration.Ini/tests/Microsoft.Extensions.Configuration.Ini.Tests.csproj b/src/libraries/Microsoft.Extensions.Configuration.Ini/tests/Microsoft.Extensions.Configuration.Ini.Tests.csproj
index 66885a90011aa3..28d3dcb8efe1fa 100644
--- a/src/libraries/Microsoft.Extensions.Configuration.Ini/tests/Microsoft.Extensions.Configuration.Ini.Tests.csproj
+++ b/src/libraries/Microsoft.Extensions.Configuration.Ini/tests/Microsoft.Extensions.Configuration.Ini.Tests.csproj
@@ -3,9 +3,6 @@
$(NetCoreAppCurrent);$(NetFrameworkCurrent)
true
-
- false
- false
diff --git a/src/libraries/Microsoft.Extensions.Configuration.Json/tests/Microsoft.Extensions.Configuration.Json.Tests.csproj b/src/libraries/Microsoft.Extensions.Configuration.Json/tests/Microsoft.Extensions.Configuration.Json.Tests.csproj
index 45433e2ff6f2bf..eef49b47827a3e 100644
--- a/src/libraries/Microsoft.Extensions.Configuration.Json/tests/Microsoft.Extensions.Configuration.Json.Tests.csproj
+++ b/src/libraries/Microsoft.Extensions.Configuration.Json/tests/Microsoft.Extensions.Configuration.Json.Tests.csproj
@@ -3,9 +3,6 @@
$(NetCoreAppCurrent);$(NetFrameworkCurrent)
true
-
- false
- false
diff --git a/src/libraries/Microsoft.Extensions.Configuration/tests/Microsoft.Extensions.Configuration.Tests.csproj b/src/libraries/Microsoft.Extensions.Configuration/tests/Microsoft.Extensions.Configuration.Tests.csproj
index f0e0bb27ea1be0..91ef2601d28568 100644
--- a/src/libraries/Microsoft.Extensions.Configuration/tests/Microsoft.Extensions.Configuration.Tests.csproj
+++ b/src/libraries/Microsoft.Extensions.Configuration/tests/Microsoft.Extensions.Configuration.Tests.csproj
@@ -2,9 +2,6 @@
$(NetCoreAppCurrent);$(NetFrameworkCurrent)
-
- false
- false
diff --git a/src/libraries/Microsoft.Extensions.DependencyInjection/tests/DI.External.Tests/Microsoft.Extensions.DependencyInjection.ExternalContainers.Tests.csproj b/src/libraries/Microsoft.Extensions.DependencyInjection/tests/DI.External.Tests/Microsoft.Extensions.DependencyInjection.ExternalContainers.Tests.csproj
index 85b40c331155e2..e809e2dac714b1 100644
--- a/src/libraries/Microsoft.Extensions.DependencyInjection/tests/DI.External.Tests/Microsoft.Extensions.DependencyInjection.ExternalContainers.Tests.csproj
+++ b/src/libraries/Microsoft.Extensions.DependencyInjection/tests/DI.External.Tests/Microsoft.Extensions.DependencyInjection.ExternalContainers.Tests.csproj
@@ -4,8 +4,6 @@
$(NetCoreAppCurrent);$(NetFrameworkCurrent)
true
$(NoWarn);CS8002
-
- false
diff --git a/src/libraries/Microsoft.Extensions.HostFactoryResolver/tests/Microsoft.Extensions.HostFactoryResolver.Tests.csproj b/src/libraries/Microsoft.Extensions.HostFactoryResolver/tests/Microsoft.Extensions.HostFactoryResolver.Tests.csproj
index 753f6940f13029..7fdb88d94c1b40 100644
--- a/src/libraries/Microsoft.Extensions.HostFactoryResolver/tests/Microsoft.Extensions.HostFactoryResolver.Tests.csproj
+++ b/src/libraries/Microsoft.Extensions.HostFactoryResolver/tests/Microsoft.Extensions.HostFactoryResolver.Tests.csproj
@@ -3,8 +3,6 @@
$(NetCoreAppCurrent);$(NetFrameworkCurrent)
enable
-
- false
diff --git a/src/libraries/System.DirectoryServices/tests/System.DirectoryServices.Tests.csproj b/src/libraries/System.DirectoryServices/tests/System.DirectoryServices.Tests.csproj
index e350bacc3b355f..6b6fb4db2a5f69 100644
--- a/src/libraries/System.DirectoryServices/tests/System.DirectoryServices.Tests.csproj
+++ b/src/libraries/System.DirectoryServices/tests/System.DirectoryServices.Tests.csproj
@@ -3,8 +3,6 @@
$(NoWarn);SYSLIB0003
$(NetCoreAppCurrent)-windows;$(NetFrameworkCurrent)
-
- false
diff --git a/src/libraries/System.IO.Packaging/tests/System.IO.Packaging.Tests.csproj b/src/libraries/System.IO.Packaging/tests/System.IO.Packaging.Tests.csproj
index d01759d746cb6c..90f1554700b357 100644
--- a/src/libraries/System.IO.Packaging/tests/System.IO.Packaging.Tests.csproj
+++ b/src/libraries/System.IO.Packaging/tests/System.IO.Packaging.Tests.csproj
@@ -1,8 +1,6 @@
$(NetCoreAppCurrent);$(NetFrameworkCurrent)
-
- false
diff --git a/src/libraries/System.Management/tests/System.Management.Tests.csproj b/src/libraries/System.Management/tests/System.Management.Tests.csproj
index 8d7d8b39d30586..ad44bb1733676b 100644
--- a/src/libraries/System.Management/tests/System.Management.Tests.csproj
+++ b/src/libraries/System.Management/tests/System.Management.Tests.csproj
@@ -1,9 +1,6 @@
$(NetCoreAppCurrent)-windows;$(NetFrameworkCurrent)
-
- false
- false
diff --git a/src/libraries/System.Net.Http.WinHttpHandler/tests/UnitTests/System.Net.Http.WinHttpHandler.Unit.Tests.csproj b/src/libraries/System.Net.Http.WinHttpHandler/tests/UnitTests/System.Net.Http.WinHttpHandler.Unit.Tests.csproj
index 10c5a92561a0e1..edabede4649558 100644
--- a/src/libraries/System.Net.Http.WinHttpHandler/tests/UnitTests/System.Net.Http.WinHttpHandler.Unit.Tests.csproj
+++ b/src/libraries/System.Net.Http.WinHttpHandler/tests/UnitTests/System.Net.Http.WinHttpHandler.Unit.Tests.csproj
@@ -5,8 +5,6 @@
..\..\src\Resources\Strings.resx
$(NetCoreAppCurrent)-windows
$(DefineConstants);UNITTEST
-
- false
diff --git a/src/libraries/System.Net.Mail/tests/Functional/System.Net.Mail.Functional.Tests.csproj b/src/libraries/System.Net.Mail/tests/Functional/System.Net.Mail.Functional.Tests.csproj
index 74c4b3dd6d1474..fd923d17919c92 100644
--- a/src/libraries/System.Net.Mail/tests/Functional/System.Net.Mail.Functional.Tests.csproj
+++ b/src/libraries/System.Net.Mail/tests/Functional/System.Net.Mail.Functional.Tests.csproj
@@ -5,8 +5,6 @@
true
true
true
-
- false
diff --git a/src/libraries/System.Net.Quic/tests/FunctionalTests/System.Net.Quic.Functional.Tests.csproj b/src/libraries/System.Net.Quic/tests/FunctionalTests/System.Net.Quic.Functional.Tests.csproj
index 2d1f2b08291682..29cacbc56ddffe 100644
--- a/src/libraries/System.Net.Quic/tests/FunctionalTests/System.Net.Quic.Functional.Tests.csproj
+++ b/src/libraries/System.Net.Quic/tests/FunctionalTests/System.Net.Quic.Functional.Tests.csproj
@@ -5,8 +5,6 @@
$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-linux;$(NetCoreAppCurrent)-osx
true
../../src/Resources/Strings.resx
-
- false
diff --git a/src/libraries/System.Net.Security/tests/FunctionalTests/System.Net.Security.Tests.csproj b/src/libraries/System.Net.Security/tests/FunctionalTests/System.Net.Security.Tests.csproj
index e8c82b958c5b6b..79610468fe7995 100644
--- a/src/libraries/System.Net.Security/tests/FunctionalTests/System.Net.Security.Tests.csproj
+++ b/src/libraries/System.Net.Security/tests/FunctionalTests/System.Net.Security.Tests.csproj
@@ -6,8 +6,6 @@
true
true
true
-
- false
diff --git a/src/libraries/System.Net.WebProxy/tests/System.Net.WebProxy.Tests.csproj b/src/libraries/System.Net.WebProxy/tests/System.Net.WebProxy.Tests.csproj
index 2084e9062abc16..b4667242cfd3ba 100644
--- a/src/libraries/System.Net.WebProxy/tests/System.Net.WebProxy.Tests.csproj
+++ b/src/libraries/System.Net.WebProxy/tests/System.Net.WebProxy.Tests.csproj
@@ -1,8 +1,6 @@
$(NetCoreAppCurrent)
-
- false
diff --git a/src/libraries/System.Net.WebSockets.Client/tests/System.Net.WebSockets.Client.Tests.csproj b/src/libraries/System.Net.WebSockets.Client/tests/System.Net.WebSockets.Client.Tests.csproj
index 9e3e7692fb3089..83cf148c6a9fd6 100644
--- a/src/libraries/System.Net.WebSockets.Client/tests/System.Net.WebSockets.Client.Tests.csproj
+++ b/src/libraries/System.Net.WebSockets.Client/tests/System.Net.WebSockets.Client.Tests.csproj
@@ -8,8 +8,6 @@
$(DefineConstants);NETSTANDARD
$(NoWarn);xUnit1015
-
- false
diff --git a/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/ComInterfaceGenerator.Unit.Tests.csproj b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/ComInterfaceGenerator.Unit.Tests.csproj
index 352dc16632dd33..9ce73c44b35c9e 100644
--- a/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/ComInterfaceGenerator.Unit.Tests.csproj
+++ b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/ComInterfaceGenerator.Unit.Tests.csproj
@@ -7,8 +7,6 @@
enable
true
../../gen/Common/Resources/Strings.resx
-
- false
diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.ComDisabled.UnitTests/System.Runtime.InteropServices.ComDisabled.Tests.csproj b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.ComDisabled.UnitTests/System.Runtime.InteropServices.ComDisabled.Tests.csproj
index 8831526b3d94f9..d54fcd8a3e9ae9 100644
--- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.ComDisabled.UnitTests/System.Runtime.InteropServices.ComDisabled.Tests.csproj
+++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.ComDisabled.UnitTests/System.Runtime.InteropServices.ComDisabled.Tests.csproj
@@ -5,8 +5,6 @@
true
true
-
- false
diff --git a/src/libraries/System.Runtime.Serialization.Primitives/tests/System.Runtime.Serialization.Primitives.Tests.csproj b/src/libraries/System.Runtime.Serialization.Primitives/tests/System.Runtime.Serialization.Primitives.Tests.csproj
index 3b807fd636ac13..bef1cc634e6373 100644
--- a/src/libraries/System.Runtime.Serialization.Primitives/tests/System.Runtime.Serialization.Primitives.Tests.csproj
+++ b/src/libraries/System.Runtime.Serialization.Primitives/tests/System.Runtime.Serialization.Primitives.Tests.csproj
@@ -1,9 +1,6 @@
$(NetCoreAppCurrent)
-
- false
- false
diff --git a/src/libraries/System.Runtime/tests/System.Buffers.Tests/System.Buffers.Tests.csproj b/src/libraries/System.Runtime/tests/System.Buffers.Tests/System.Buffers.Tests.csproj
index 39828a91ff6d9a..113d56e6f43635 100644
--- a/src/libraries/System.Runtime/tests/System.Buffers.Tests/System.Buffers.Tests.csproj
+++ b/src/libraries/System.Runtime/tests/System.Buffers.Tests/System.Buffers.Tests.csproj
@@ -4,8 +4,6 @@
true
true
$(NetCoreAppCurrent)
-
- false
true
diff --git a/src/libraries/System.Runtime/tests/System.Reflection.Tests/CoreCLR/System.Reflection.CoreCLR.Tests.csproj b/src/libraries/System.Runtime/tests/System.Reflection.Tests/CoreCLR/System.Reflection.CoreCLR.Tests.csproj
index ac2edc0f775ab5..ea0343e7811d73 100644
--- a/src/libraries/System.Runtime/tests/System.Reflection.Tests/CoreCLR/System.Reflection.CoreCLR.Tests.csproj
+++ b/src/libraries/System.Runtime/tests/System.Reflection.Tests/CoreCLR/System.Reflection.CoreCLR.Tests.csproj
@@ -2,8 +2,6 @@
$(NetCoreAppCurrent)
true
-
- false
diff --git a/src/libraries/System.Runtime/tests/System.Runtime.InteropServices.RuntimeInformation.Tests/System.Runtime.InteropServices.RuntimeInformation.Tests.csproj b/src/libraries/System.Runtime/tests/System.Runtime.InteropServices.RuntimeInformation.Tests/System.Runtime.InteropServices.RuntimeInformation.Tests.csproj
index 25dbbb548cd920..b21850df267dfa 100644
--- a/src/libraries/System.Runtime/tests/System.Runtime.InteropServices.RuntimeInformation.Tests/System.Runtime.InteropServices.RuntimeInformation.Tests.csproj
+++ b/src/libraries/System.Runtime/tests/System.Runtime.InteropServices.RuntimeInformation.Tests/System.Runtime.InteropServices.RuntimeInformation.Tests.csproj
@@ -3,8 +3,6 @@
true
true
$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-unix;$(NetCoreAppCurrent)-browser
-
- false
$(DefineConstants);STABILIZE_PACKAGE_VERSION
diff --git a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/InvokeEmit/System.Runtime.ReflectionInvokeEmit.Tests.csproj b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/InvokeEmit/System.Runtime.ReflectionInvokeEmit.Tests.csproj
index c64c1e3a1e55b9..4188e399626e99 100644
--- a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/InvokeEmit/System.Runtime.ReflectionInvokeEmit.Tests.csproj
+++ b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/InvokeEmit/System.Runtime.ReflectionInvokeEmit.Tests.csproj
@@ -4,8 +4,6 @@
true
true
$(NetCoreAppCurrent)
-
- false
diff --git a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/InvokeInterpreted/System.Runtime.ReflectionInvokeInterpreted.Tests.csproj b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/InvokeInterpreted/System.Runtime.ReflectionInvokeInterpreted.Tests.csproj
index c64c1e3a1e55b9..4188e399626e99 100644
--- a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/InvokeInterpreted/System.Runtime.ReflectionInvokeInterpreted.Tests.csproj
+++ b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/InvokeInterpreted/System.Runtime.ReflectionInvokeInterpreted.Tests.csproj
@@ -4,8 +4,6 @@
true
true
$(NetCoreAppCurrent)
-
- false
diff --git a/src/libraries/System.Runtime/tests/System.Threading.Tasks.Extensions.Tests/System.Threading.Tasks.Extensions.Tests.csproj b/src/libraries/System.Runtime/tests/System.Threading.Tasks.Extensions.Tests/System.Threading.Tasks.Extensions.Tests.csproj
index 952e5ec237e5da..44cf712d71c7c2 100644
--- a/src/libraries/System.Runtime/tests/System.Threading.Tasks.Extensions.Tests/System.Threading.Tasks.Extensions.Tests.csproj
+++ b/src/libraries/System.Runtime/tests/System.Threading.Tasks.Extensions.Tests/System.Threading.Tasks.Extensions.Tests.csproj
@@ -3,8 +3,6 @@
$(NetCoreAppCurrent)
true
true
-
- false
diff --git a/src/libraries/System.Security.Cryptography.Pkcs/tests/System.Security.Cryptography.Pkcs.Tests.csproj b/src/libraries/System.Security.Cryptography.Pkcs/tests/System.Security.Cryptography.Pkcs.Tests.csproj
index ac150e7c612e1d..ee52068c8a26ce 100644
--- a/src/libraries/System.Security.Cryptography.Pkcs/tests/System.Security.Cryptography.Pkcs.Tests.csproj
+++ b/src/libraries/System.Security.Cryptography.Pkcs/tests/System.Security.Cryptography.Pkcs.Tests.csproj
@@ -4,8 +4,6 @@
$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent);$(NetFrameworkCurrent)
$(NoWarn);SYSLIB0057
$(NoWarn);SYSLIB5006
-
- false
true
false
-
- false
diff --git a/src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/System.Text.Json.SourceGeneration.Roslyn4.4.Unit.Tests.csproj b/src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/System.Text.Json.SourceGeneration.Roslyn4.4.Unit.Tests.csproj
index 89318aec9c5b5d..b453e5051e1693 100644
--- a/src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/System.Text.Json.SourceGeneration.Roslyn4.4.Unit.Tests.csproj
+++ b/src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/System.Text.Json.SourceGeneration.Roslyn4.4.Unit.Tests.csproj
@@ -3,8 +3,6 @@
$(MicrosoftCodeAnalysisVersion_4_8)
$(DefineConstants);ROSLYN4_0_OR_GREATER;ROSLYN4_4_OR_GREATER
true
-
- false
diff --git a/src/libraries/System.Threading.RateLimiting/tests/System.Threading.RateLimiting.Tests.csproj b/src/libraries/System.Threading.RateLimiting/tests/System.Threading.RateLimiting.Tests.csproj
index 0169f249b4a2e5..8d1e0c48959af4 100644
--- a/src/libraries/System.Threading.RateLimiting/tests/System.Threading.RateLimiting.Tests.csproj
+++ b/src/libraries/System.Threading.RateLimiting/tests/System.Threading.RateLimiting.Tests.csproj
@@ -2,8 +2,6 @@
$(NetCoreAppCurrent);$(NetFrameworkCurrent)
-
- false
From 0150f13ea604210ce384c7cfc576e9487da6ec6c Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Tue, 19 May 2026 02:43:40 +0000
Subject: [PATCH 2/8] Suppress trim and AOT analyzer warnings in tests
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/5977beb1-58f4-4a75-9a1c-02ff1bb17294
Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
---
.../Common/tests/SourceGenerators/GeneratorTestHelpers.cs | 4 ++++
.../tests/System/Threading/Tasks/GetStateMachineData.cs | 6 ++++++
.../tests/ConfigurationProviderTestBase.cs | 2 ++
.../SkippableDependencyInjectionSpecificationTests.cs | 2 ++
.../src/HostFactoryResolver.cs | 6 ++++++
src/libraries/System.IO.Packaging/tests/PartPieceTests.cs | 2 ++
.../System.Net.Mail/tests/Functional/MailMessageTest.cs | 2 ++
.../tests/FunctionalTests/MsQuicInteropTests.cs | 6 ++++++
.../FunctionalTests/SslStreamNegotiatedCipherSuiteTest.cs | 2 ++
src/libraries/System.Net.WebProxy/tests/WebProxyTest.cs | 6 ++++++
.../tests/CloseTest.Loopback.cs | 2 ++
.../tests/ComInterfaceGenerator.Unit.Tests/CodeSnippets.cs | 2 ++
.../InteropServices/Marshal/MarshalComDisabledTests.cs | 2 ++
.../Serialization/InvalidDataContractExceptionTests.cs | 4 ++++
.../tests/System.Buffers.Tests/ArrayPool/CollectionTests.cs | 2 ++
.../tests/System.Reflection.Tests/CoreCLR/AssemblyTests.cs | 4 ++++
.../DescriptionNameTests.cs | 2 ++
.../System/Reflection/BindingFlagsDoNotWrap.cs | 4 ++++
.../tests/CmsRecipientCollectionTests.cs | 2 ++
.../tests/CryptographicAttributeObjectCollectionTests.cs | 2 ++
.../tests/RecipientInfoCollectionTests.cs | 2 ++
.../JsonSourceGeneratorIncrementalTests.cs | 2 ++
.../tests/Infrastructure/Utils.cs | 4 ++++
23 files changed, 72 insertions(+)
diff --git a/src/libraries/Common/tests/SourceGenerators/GeneratorTestHelpers.cs b/src/libraries/Common/tests/SourceGenerators/GeneratorTestHelpers.cs
index d62a3c788e73dc..96766027c61b36 100644
--- a/src/libraries/Common/tests/SourceGenerators/GeneratorTestHelpers.cs
+++ b/src/libraries/Common/tests/SourceGenerators/GeneratorTestHelpers.cs
@@ -59,10 +59,14 @@ static void CheckAreEqualCore(object expected, object actual, Stack path
}
}
+#pragma warning disable IL2075
if (type.GetProperty("EqualityContract", BindingFlags.Instance | BindingFlags.NonPublic, null, returnType: typeof(Type), types: Array.Empty(), null) != null)
+#pragma warning restore IL2075
{
// Type is a C# record, run pointwise equality comparison.
+#pragma warning disable IL2075
foreach (PropertyInfo property in type.GetProperties(BindingFlags.Public | BindingFlags.Instance))
+#pragma warning restore IL2075
{
path.Push("." + property.Name);
CheckAreEqualCore(property.GetValue(expected), property.GetValue(actual), path);
diff --git a/src/libraries/Common/tests/System/Threading/Tasks/GetStateMachineData.cs b/src/libraries/Common/tests/System/Threading/Tasks/GetStateMachineData.cs
index 21f83967fb8ba8..f81bd9e2cd2dd2 100644
--- a/src/libraries/Common/tests/System/Threading/Tasks/GetStateMachineData.cs
+++ b/src/libraries/Common/tests/System/Threading/Tasks/GetStateMachineData.cs
@@ -54,7 +54,9 @@ static void Describe(object box, StringBuilder sb, HashSet
-
+
From 768bc811fb055fcb086f2ed0afec3423cfb57525 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Tue, 19 May 2026 04:32:31 +0000
Subject: [PATCH 4/8] Use null-safe DiagnosticMethodInfo in DI tests
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/5a0b0c7b-d13e-4936-8392-ff08d859bc72
Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
---
.../SkippableDependencyInjectionSpecificationTests.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/libraries/Microsoft.Extensions.DependencyInjection/tests/DI.External.Tests/SkippableDependencyInjectionSpecificationTests.cs b/src/libraries/Microsoft.Extensions.DependencyInjection/tests/DI.External.Tests/SkippableDependencyInjectionSpecificationTests.cs
index 4a77023a1a37b2..72171bc6742f96 100644
--- a/src/libraries/Microsoft.Extensions.DependencyInjection/tests/DI.External.Tests/SkippableDependencyInjectionSpecificationTests.cs
+++ b/src/libraries/Microsoft.Extensions.DependencyInjection/tests/DI.External.Tests/SkippableDependencyInjectionSpecificationTests.cs
@@ -16,7 +16,7 @@ protected sealed override IServiceProvider CreateServiceProvider(IServiceCollect
{
foreach (var stackFrame in new StackTrace(1).GetFrames().Take(2))
{
- if (SkippedTests.Contains(DiagnosticMethodInfo.Create(stackFrame).Name))
+ if (SkippedTests.Contains(DiagnosticMethodInfo.Create(stackFrame)?.Name))
{
// We skip tests by returning MEDI service provider that we know passes the test
return serviceCollection.BuildServiceProvider();
From 7d17a32de212127f106b023f2f9574224ab3b443 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Thu, 21 May 2026 05:27:19 +0000
Subject: [PATCH 5/8] Address additional analyzer review feedback
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/087bc9c5-a2a7-4eea-becd-4a9625ddce15
Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
---
.../SourceGenerators/GeneratorTestHelpers.cs | 6 +-
.../Threading/Tasks/GetStateMachineData.cs | 95 +------------------
.../GeneratorTests.Incremental.cs | 2 +
.../tests/ConfigurationProviderTestBase.cs | 2 +-
.../src/HostFactoryResolver.cs | 6 --
...xtensions.HostFactoryResolver.Tests.csproj | 2 +
.../tests/FunctionalTests/Watchdog.cs | 13 +--
.../tests/Functional/MailMessageTest.cs | 2 +-
.../FunctionalTests/MsQuicInteropTests.cs | 31 +++---
.../tests/CloseTest.Loopback.cs | 2 +-
.../CodeSnippets.cs | 2 +-
.../Marshal/MarshalComDisabledTests.cs | 2 +-
.../InvalidDataContractExceptionTests.cs | 7 +-
.../ArrayPool/CollectionTests.cs | 2 +-
.../CoreCLR/AssemblyTests.cs | 4 +-
.../DescriptionNameTests.cs | 2 +-
.../Reflection/BindingFlagsDoNotWrap.cs | 4 +-
.../tests/CmsRecipientCollectionTests.cs | 2 +-
...tographicAttributeObjectCollectionTests.cs | 2 +-
.../tests/RecipientInfoCollectionTests.cs | 2 +-
.../JsonSourceGeneratorIncrementalTests.cs | 6 +-
21 files changed, 47 insertions(+), 149 deletions(-)
diff --git a/src/libraries/Common/tests/SourceGenerators/GeneratorTestHelpers.cs b/src/libraries/Common/tests/SourceGenerators/GeneratorTestHelpers.cs
index 96766027c61b36..1fc0fdc06ab040 100644
--- a/src/libraries/Common/tests/SourceGenerators/GeneratorTestHelpers.cs
+++ b/src/libraries/Common/tests/SourceGenerators/GeneratorTestHelpers.cs
@@ -4,6 +4,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using Xunit;
@@ -15,6 +16,7 @@ internal static class GeneratorTestHelpers
///
/// Asserts for structural equality, returning a path to the mismatching data when not equal.
///
+ [RequiresUnreferencedCode("Checks structural equality using reflection")]
public static void AssertStructurallyEqual(T expected, T actual)
{
CheckAreEqualCore(expected, actual, new());
@@ -59,14 +61,10 @@ static void CheckAreEqualCore(object expected, object actual, Stack path
}
}
-#pragma warning disable IL2075
if (type.GetProperty("EqualityContract", BindingFlags.Instance | BindingFlags.NonPublic, null, returnType: typeof(Type), types: Array.Empty(), null) != null)
-#pragma warning restore IL2075
{
// Type is a C# record, run pointwise equality comparison.
-#pragma warning disable IL2075
foreach (PropertyInfo property in type.GetProperties(BindingFlags.Public | BindingFlags.Instance))
-#pragma warning restore IL2075
{
path.Push("." + property.Name);
CheckAreEqualCore(property.GetValue(expected), property.GetValue(actual), path);
diff --git a/src/libraries/Common/tests/System/Threading/Tasks/GetStateMachineData.cs b/src/libraries/Common/tests/System/Threading/Tasks/GetStateMachineData.cs
index f81bd9e2cd2dd2..422f3b7b831b8a 100644
--- a/src/libraries/Common/tests/System/Threading/Tasks/GetStateMachineData.cs
+++ b/src/libraries/Common/tests/System/Threading/Tasks/GetStateMachineData.cs
@@ -1,22 +1,14 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System.Collections.Generic;
-using System.Linq;
-using System.Reflection;
using System.Runtime.CompilerServices;
-using System.Text;
namespace System.Threading.Tasks
{
///
- /// Fragile trick for getting a description of the current state of a .NET Core async method state machine.
- /// To use, first await FetchAsync to get back an object:
+ /// Fragile trick for getting the current state of a .NET Core async method state machine.
+ /// To use, await FetchAsync to get back an object:
/// object box = await GetStateMachineData.FetchAsync();
- /// and then when the description is desired, use:
- /// string description = GetStateMachineData.Describe(box);
- /// For example:
- /// using (new Timer(s => Console.WriteLine(GetStateMachineData.Describe(s)), await GetStateMachineData.FetchAsync(), 60_000, 60_000))
///
internal sealed class GetStateMachineData : ICriticalNotifyCompletion
{
@@ -25,89 +17,6 @@ internal sealed class GetStateMachineData : ICriticalNotifyCompletion
/// Returns an awaitable whose awaited result will be the boxed state machine for the async method.
public static GetStateMachineData FetchAsync() => new GetStateMachineData();
- /// Creates a string representation of a boxed state machine object.
- public static string Describe(object box)
- {
- var sb = new StringBuilder();
- var seen = new HashSet();
- Describe(box, sb, seen, 0);
- return sb.ToString();
-
- static void Describe(object box, StringBuilder sb, HashSet seen, int indentLevel)
- {
- string indent = string.Concat(Enumerable.Repeat(" ", indentLevel));
-
- // If we were handed a null object (which should only happen from recursion),
- // state that the object was null.
- if (box is null)
- {
- sb.Append(indent).AppendLine($"(Object was null.)");
- return;
- }
-
- // If as we're walking a graph we happen upon a cycle, break it.
- if (!seen.Add(box))
- {
- sb.Append(indent).AppendLine($"(Object already seen in graph walk.)");
- return;
- }
-
- // Try to get the StateMachine field from the AsyncStateMachineBox<>. If we can't,
- // just print out the details we can and bail.
-#pragma warning disable IL2075
- FieldInfo stateMachineField = box.GetType().GetField("StateMachine", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
-#pragma warning restore IL2075
- if (stateMachineField is null)
- {
- sb.Append(indent).AppendLine($"(Couldn't get state machine field from {box}.)");
- sb.Append(indent).AppendLine(ToString(box));
- return;
- }
-
- // Get the state machine from the StateMachine field.
- IAsyncStateMachine stateMachine = stateMachineField.GetValue(box) as IAsyncStateMachine;
- if (stateMachine is null)
- {
- sb.Append(indent).AppendLine($"(Null state machine from {box}.)");
- return;
- }
-
- // Print out the name of the state machine.
- Type stateMachineType = stateMachine.GetType();
- sb.Append(indent).AppendLine(stateMachineType.FullName);
-
- // Get all of the fields on the state machine, and print them all out.
-#pragma warning disable IL2075
- FieldInfo[] fields = stateMachineType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
-#pragma warning restore IL2075
- foreach (FieldInfo fi in fields)
- {
- // Print out the field name and its value.
- object fiValue = fi.GetValue(stateMachine);
- sb.Append(indent).AppendLine($" {fi.Name}: {ToString(fiValue)}");
-
- // If the field is an awaiter, recursively examine any tasks it directly references.
- if (fiValue is ICriticalNotifyCompletion)
- {
-#pragma warning disable IL2075
- foreach (FieldInfo possibleTask in fiValue.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
-#pragma warning restore IL2075
- {
- if (possibleTask.GetValue(fiValue) is Task awaitedTask)
- {
- Describe(awaitedTask, sb, seen, indentLevel + 1);
- }
- }
- }
- }
- }
-
- static string ToString(object value) =>
- value is null ? "(null)" :
- value is Task t ? $"Status: {t.Status}, Exception: {t.Exception?.InnerException}" :
- value.ToString();
- }
-
private GetStateMachineData() { }
public GetStateMachineData GetAwaiter() => this;
public bool IsCompleted => false;
diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/GeneratorTests.Incremental.cs b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/GeneratorTests.Incremental.cs
index bb6c5baae32272..30d533cd4e5ad6 100644
--- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/GeneratorTests.Incremental.cs
+++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/GeneratorTests.Incremental.cs
@@ -22,7 +22,9 @@ public async Task CompilingTheSameSourceResultsInEqualModels()
SourceGenerationSpec spec2 = (await new ConfigBindingGenTestDriver().RunGeneratorAndUpdateCompilation(BindCallSampleCode)).GenerationSpec;
Assert.NotSame(spec1, spec2);
+#pragma warning disable IL2026 // Checks structural equality using reflection
GeneratorTestHelpers.AssertStructurallyEqual(spec1, spec2);
+#pragma warning restore IL2026
Assert.Equal(spec1, spec2);
Assert.Equal(spec1.GetHashCode(), spec2.GetHashCode());
diff --git a/src/libraries/Microsoft.Extensions.Configuration/tests/ConfigurationProviderTestBase.cs b/src/libraries/Microsoft.Extensions.Configuration/tests/ConfigurationProviderTestBase.cs
index cc2c1498326090..b8da228e475ded 100644
--- a/src/libraries/Microsoft.Extensions.Configuration/tests/ConfigurationProviderTestBase.cs
+++ b/src/libraries/Microsoft.Extensions.Configuration/tests/ConfigurationProviderTestBase.cs
@@ -130,7 +130,7 @@ public virtual void Bind_to_object()
{
var configuration = BuildConfigRoot(LoadThroughProvider(TestSection.TestConfig));
-#pragma warning disable IL2026, IL3050
+#pragma warning disable IL2026, IL3050 // https://github.com/dotnet/runtime/issues/126862
var options = configuration.Get();
#pragma warning restore IL2026, IL3050
diff --git a/src/libraries/Microsoft.Extensions.HostFactoryResolver/src/HostFactoryResolver.cs b/src/libraries/Microsoft.Extensions.HostFactoryResolver/src/HostFactoryResolver.cs
index dff588b409d06e..cc8a86d84e1a56 100644
--- a/src/libraries/Microsoft.Extensions.HostFactoryResolver/src/HostFactoryResolver.cs
+++ b/src/libraries/Microsoft.Extensions.HostFactoryResolver/src/HostFactoryResolver.cs
@@ -100,9 +100,7 @@ private static TimeSpan SetupDefaultTimeout()
return null;
}
-#pragma warning disable IL2075
var factory = programType.GetMethod(name, DeclaredOnlyLookup);
-#pragma warning restore IL2075
if (!IsFactory(factory))
{
return null;
@@ -180,9 +178,7 @@ static bool IsApplicationNameArg(string arg)
private static object? Build(object builder)
{
-#pragma warning disable IL2075
var buildMethod = builder.GetType().GetMethod("Build");
-#pragma warning restore IL2075
return buildMethod?.Invoke(builder, Array.Empty());
}
@@ -193,9 +189,7 @@ static bool IsApplicationNameArg(string arg)
return null;
}
var hostType = host.GetType();
-#pragma warning disable IL2075
var servicesProperty = hostType.GetProperty("Services", DeclaredOnlyLookup);
-#pragma warning restore IL2075
return (IServiceProvider?)servicesProperty?.GetValue(host);
}
diff --git a/src/libraries/Microsoft.Extensions.HostFactoryResolver/tests/Microsoft.Extensions.HostFactoryResolver.Tests.csproj b/src/libraries/Microsoft.Extensions.HostFactoryResolver/tests/Microsoft.Extensions.HostFactoryResolver.Tests.csproj
index 7fdb88d94c1b40..753f6940f13029 100644
--- a/src/libraries/Microsoft.Extensions.HostFactoryResolver/tests/Microsoft.Extensions.HostFactoryResolver.Tests.csproj
+++ b/src/libraries/Microsoft.Extensions.HostFactoryResolver/tests/Microsoft.Extensions.HostFactoryResolver.Tests.csproj
@@ -3,6 +3,8 @@
$(NetCoreAppCurrent);$(NetFrameworkCurrent)
enable
+
+ false
diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/Watchdog.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/Watchdog.cs
index 0efadfc3e1bfd7..09dbbd07aad87f 100644
--- a/src/libraries/System.Net.Http/tests/FunctionalTests/Watchdog.cs
+++ b/src/libraries/System.Net.Http/tests/FunctionalTests/Watchdog.cs
@@ -2,9 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
using System;
-using System.Collections.Generic;
using System.Runtime.CompilerServices;
-using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Xunit;
@@ -13,7 +11,7 @@ namespace System.Net.Http.Functional.Tests
{
///
/// This is using similar trick to GetStateMachineData
- /// If marked test runs for more than 60s it will print machine state and make sure it fails
+ /// If marked test runs for more than 60s it will make sure it fails
/// Usage (await MUST be run directly in the test, should not be called from other async method):
/// using (await Watchdog.CreateAsync())
/// {
@@ -30,7 +28,7 @@ public static Watchdog CreateAsync()
=> new Watchdog();
public IDisposable GetResult()
- => new WatchdogImpl(_box);
+ => new WatchdogImpl();
public Watchdog GetAwaiter() => this;
public bool IsCompleted => false;
@@ -46,14 +44,13 @@ private class WatchdogImpl : IDisposable
private bool _passed = true;
private Timer _timer;
- public WatchdogImpl(object stateMachineData)
+ public WatchdogImpl()
{
- _timer = new Timer(s =>
+ _timer = new Timer(_ =>
{
_passed = false;
- Console.WriteLine(GetStateMachineData.Describe(s));
},
- stateMachineData,
+ null,
60_000,
60_000);
}
diff --git a/src/libraries/System.Net.Mail/tests/Functional/MailMessageTest.cs b/src/libraries/System.Net.Mail/tests/Functional/MailMessageTest.cs
index ad6fade9a530ad..b3d3d89e77aa26 100644
--- a/src/libraries/System.Net.Mail/tests/Functional/MailMessageTest.cs
+++ b/src/libraries/System.Net.Mail/tests/Functional/MailMessageTest.cs
@@ -264,7 +264,7 @@ private static (string Raw, string Attachment) DecodeSentMailMessage(MailMessage
var syncSendAdapterType = Type.GetType("System.Net.SyncReadWriteAdapter, System.Net.Mail");
// Send the message.
-#pragma warning disable IL3050
+#pragma warning disable IL3050 // Roslyn analyzer can't see through the private reflection, but publish process can. This is safe.
typeof(MailMessage)
.GetMethod("SendAsync", BindingFlags.Instance | BindingFlags.NonPublic)
.MakeGenericMethod(syncSendAdapterType)
diff --git a/src/libraries/System.Net.Quic/tests/FunctionalTests/MsQuicInteropTests.cs b/src/libraries/System.Net.Quic/tests/FunctionalTests/MsQuicInteropTests.cs
index 69ea64a4f4c809..3fd98d50b13097 100644
--- a/src/libraries/System.Net.Quic/tests/FunctionalTests/MsQuicInteropTests.cs
+++ b/src/libraries/System.Net.Quic/tests/FunctionalTests/MsQuicInteropTests.cs
@@ -3,11 +3,12 @@
using System;
using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
+using System.Linq;
using System.Net.Security;
-using System.Threading.Tasks;
-using System.Runtime.InteropServices;
using System.Reflection;
-using System.Linq;
+using System.Runtime.InteropServices;
+using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;
@@ -17,38 +18,28 @@ namespace System.Net.Quic.Tests
{
public class MsQuicInteropTests
{
- private static MemberInfo[] GetMembers()
+ private static MemberInfo[] GetMembers<
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields | DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.NonPublicProperties)] T>()
{
-#pragma warning disable IL2090
- var members = typeof(T).FindMembers(MemberTypes.Field | MemberTypes.Property, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public, (mi, _) =>
-#pragma warning restore IL2090
- {
- if (mi is PropertyInfo property && property.GetSetMethod() == null)
- {
- return false;
- }
-
- return true;
- }, null);
+ var members = typeof(T).GetFields(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public).Cast()
+ .Concat(typeof(T).GetProperties(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public).Where(property => property.GetSetMethod() is not null))
+ .ToArray();
Assert.NotEmpty(members);
return members;
}
+ [RequiresUnreferencedCode("Resets members using reflection")]
private static void ResetMember(MemberInfo member, object instance)
{
switch (member)
{
case FieldInfo field:
-#pragma warning disable IL2072
field.SetValue(instance, Activator.CreateInstance(field.FieldType));
-#pragma warning restore IL2072
break;
case PropertyInfo property:
-#pragma warning disable IL2072
property.SetValue(instance, Activator.CreateInstance(property.PropertyType));
-#pragma warning restore IL2072
break;
default:
throw new InvalidOperationException($"Unexpected member type: {member.MemberType}");
@@ -72,7 +63,9 @@ public void QuicSettings_Equals_RespectsAllMembers()
{
// copy and box the instance because reflection methods take a reference type arg
object boxed = settings;
+#pragma warning disable IL2026 // Resets members using reflection
ResetMember(member, boxed);
+#pragma warning restore IL2026
Assert.False(settings.Equals((QUIC_SETTINGS)boxed), $"Member {member.Name} is not compared.");
}
}
diff --git a/src/libraries/System.Net.WebSockets.Client/tests/CloseTest.Loopback.cs b/src/libraries/System.Net.WebSockets.Client/tests/CloseTest.Loopback.cs
index 47a2867c21570d..7388cdde9e2619 100644
--- a/src/libraries/System.Net.WebSockets.Client/tests/CloseTest.Loopback.cs
+++ b/src/libraries/System.Net.WebSockets.Client/tests/CloseTest.Loopback.cs
@@ -146,7 +146,7 @@ public async Task CloseHandshake_ExceptionsAreObserved()
{
await RemoteExecutor.Invoke(static (typeName) =>
{
-#pragma warning disable IL2026, IL2072
+#pragma warning disable IL2026, IL2072 // https://github.com/dotnet/runtime/issues/126862
ClientWebSocketTestBase test = (ClientWebSocketTestBase)Activator.CreateInstance(typeof(ClientWebSocketTestBase).Assembly.GetType(typeName), new object[] { null });
#pragma warning restore IL2026, IL2072
using CancellationTokenSource timeoutCts = new CancellationTokenSource(TimeOutMilliseconds);
diff --git a/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/CodeSnippets.cs b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/CodeSnippets.cs
index 6e28156119f0eb..6d00dee71f5a9f 100644
--- a/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/CodeSnippets.cs
+++ b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/CodeSnippets.cs
@@ -416,7 +416,7 @@ partial interface INativeAPI
{{_attributeProvider.AdditionalUserRequiredInterfaces("INativeAPI")}}
""";
-#pragma warning disable IL2057
+#pragma warning disable IL2057 // https://github.com/dotnet/runtime/issues/126862
public string BasicReturnTypeCustomExceptionHandling(string typeName, string customExceptionType, string preDeclaration = "") => $$"""
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.ComDisabled.UnitTests/System/Runtime/InteropServices/Marshal/MarshalComDisabledTests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.ComDisabled.UnitTests/System/Runtime/InteropServices/Marshal/MarshalComDisabledTests.cs
index bf87c366f36734..bbc9722b0421c5 100644
--- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.ComDisabled.UnitTests/System/Runtime/InteropServices/Marshal/MarshalComDisabledTests.cs
+++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.ComDisabled.UnitTests/System/Runtime/InteropServices/Marshal/MarshalComDisabledTests.cs
@@ -151,7 +151,7 @@ public void GetObjectsForNativeVariants_T_ThrowsNotSupportedException()
[Fact]
public void BindToMoniker_ThrowsNotSupportedException()
{
-#pragma warning disable IL2026
+#pragma warning disable IL2026 // With COM disabled, this always throws so it's safe
Assert.Throws(() => Marshal.BindToMoniker("test"));
#pragma warning restore IL2026
}
diff --git a/src/libraries/System.Runtime.Serialization.Primitives/tests/System/Runtime/Serialization/InvalidDataContractExceptionTests.cs b/src/libraries/System.Runtime.Serialization.Primitives/tests/System/Runtime/Serialization/InvalidDataContractExceptionTests.cs
index 45bda684d2f6bf..396ecd9fde95aa 100644
--- a/src/libraries/System.Runtime.Serialization.Primitives/tests/System/Runtime/Serialization/InvalidDataContractExceptionTests.cs
+++ b/src/libraries/System.Runtime.Serialization.Primitives/tests/System/Runtime/Serialization/InvalidDataContractExceptionTests.cs
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
+using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using Xunit;
@@ -37,19 +38,17 @@ public void Ctor_String_Exception(string message)
}
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBinaryFormatterSupported))]
+ [RequiresDynamicCode("BinaryFormatter serialization uses dynamic code generation")]
+ [RequiresUnreferencedCode("BinaryFormatter serialization is not trim compatible")]
public void Ctor_SerializationInfo_StreamingContext()
{
using (var memoryStream = new MemoryStream())
{
var formatter = new BinaryFormatter();
-#pragma warning disable IL2026
formatter.Serialize(memoryStream, new InvalidDataContractException());
-#pragma warning restore IL2026
memoryStream.Seek(0, SeekOrigin.Begin);
-#pragma warning disable IL2026, IL3050
Assert.IsType(formatter.Deserialize(memoryStream));
-#pragma warning restore IL2026, IL3050
}
}
}
diff --git a/src/libraries/System.Runtime/tests/System.Buffers.Tests/ArrayPool/CollectionTests.cs b/src/libraries/System.Runtime/tests/System.Buffers.Tests/ArrayPool/CollectionTests.cs
index 264e72d04e2589..4e1e09cb1f59b7 100644
--- a/src/libraries/System.Runtime/tests/System.Buffers.Tests/ArrayPool/CollectionTests.cs
+++ b/src/libraries/System.Runtime/tests/System.Buffers.Tests/ArrayPool/CollectionTests.cs
@@ -92,7 +92,7 @@ public unsafe void ThreadLocalIsCollectedUnderHighPressure()
const int AllocSize = 1024 * 1024 * 64;
int PageSize = Environment.SystemPageSize;
-#pragma warning disable IL2075
+#pragma warning disable IL2075 // This private reflection is broken since .NET 6
var pressureMethod = ArrayPool.Shared.GetType().GetMethod("GetMemoryPressure", BindingFlags.Static | BindingFlags.NonPublic);
#pragma warning restore IL2075
do
diff --git a/src/libraries/System.Runtime/tests/System.Reflection.Tests/CoreCLR/AssemblyTests.cs b/src/libraries/System.Runtime/tests/System.Reflection.Tests/CoreCLR/AssemblyTests.cs
index beebf86f4bf70d..0c305dfc0a0543 100644
--- a/src/libraries/System.Runtime/tests/System.Reflection.Tests/CoreCLR/AssemblyTests.cs
+++ b/src/libraries/System.Runtime/tests/System.Reflection.Tests/CoreCLR/AssemblyTests.cs
@@ -34,7 +34,7 @@ public void LoadFromStream_EmptyStream_ThrowsBadImageFormatException()
{
using (var emptyStream = new MemoryStream())
{
-#pragma warning disable IL2026
+#pragma warning disable IL2026 // https://github.com/dotnet/runtime/issues/126862
BadImageFormatException ex = Assert.Throws(
() => AssemblyLoadContext.Default.LoadFromStream(emptyStream));
#pragma warning restore IL2026
@@ -56,7 +56,7 @@ private sealed class TestStreamLoadContext : AssemblyLoadContext
{
protected override Assembly Load(AssemblyName assemblyName)
{
-#pragma warning disable IL2026
+#pragma warning disable IL2026 // https://github.com/dotnet/runtime/issues/126862
return LoadFromStream(GetExecutingAssembly().GetManifestResourceStream(assemblyName.Name + ".dll"));
#pragma warning restore IL2026
}
diff --git a/src/libraries/System.Runtime/tests/System.Runtime.InteropServices.RuntimeInformation.Tests/DescriptionNameTests.cs b/src/libraries/System.Runtime/tests/System.Runtime.InteropServices.RuntimeInformation.Tests/DescriptionNameTests.cs
index 5d0390518f7eb5..0bbc490fe98909 100644
--- a/src/libraries/System.Runtime/tests/System.Runtime.InteropServices.RuntimeInformation.Tests/DescriptionNameTests.cs
+++ b/src/libraries/System.Runtime/tests/System.Runtime.InteropServices.RuntimeInformation.Tests/DescriptionNameTests.cs
@@ -103,7 +103,7 @@ public void DumpRuntimeInformationToConsole()
sb.Append($"###\t{prop}: ");
try
{
-#pragma warning disable IL2075
+#pragma warning disable IL2075 // Not used for testing, just informational logging
sb.Append(p.GetType().GetProperty(prop).GetValue(p));
#pragma warning restore IL2075
}
diff --git a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/BindingFlagsDoNotWrap.cs b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/BindingFlagsDoNotWrap.cs
index 8146bd59d103fc..8426abc8cff149 100644
--- a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/BindingFlagsDoNotWrap.cs
+++ b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/BindingFlagsDoNotWrap.cs
@@ -133,7 +133,7 @@ public static void AssemblyCreateInstance()
{
Assembly a = typeof(TestClass).Assembly;
const BindingFlags flags = BindingFlags.Public | BindingFlags.Instance;
-#pragma warning disable IL2058
+#pragma warning disable IL2058 // https://github.com/dotnet/runtime/issues/126862
TestDoNotWrap((bf) => a.CreateInstance(typeof(TestClass).FullName, false, bf | flags, null, Array.Empty(), null, null));
#pragma warning restore IL2058
}
@@ -143,7 +143,7 @@ public static void AssemblyCreateInstance_BadCCtor()
{
Assembly a = typeof(TestClass).Assembly;
const BindingFlags flags = BindingFlags.Public | BindingFlags.Instance;
-#pragma warning disable IL2058
+#pragma warning disable IL2058 // https://github.com/dotnet/runtime/issues/126862
TestDoNotWrap((bf) => a.CreateInstance(typeof(TestClassBadCCtor).FullName, false, bf | flags, null, Array.Empty(), null, null));
#pragma warning restore IL2058
}
diff --git a/src/libraries/System.Security.Cryptography.Pkcs/tests/CmsRecipientCollectionTests.cs b/src/libraries/System.Security.Cryptography.Pkcs/tests/CmsRecipientCollectionTests.cs
index c346473d4ad1c8..54faeaf69b8432 100644
--- a/src/libraries/System.Security.Cryptography.Pkcs/tests/CmsRecipientCollectionTests.cs
+++ b/src/libraries/System.Security.Cryptography.Pkcs/tests/CmsRecipientCollectionTests.cs
@@ -172,7 +172,7 @@ public static void CopyExceptions()
if (PlatformDetection.IsNonZeroLowerBoundArraySupported)
{
// Array has non-zero lower bound
-#pragma warning disable IL3050
+#pragma warning disable IL3050 // Creating multi-dimensional arrays is AOT safe, only SzArrays are problem
Array array = Array.CreateInstance(typeof(object), new int[] { 10 }, new int[] { 10 });
#pragma warning restore IL3050
Assert.Throws(() => ic.CopyTo(array, 0));
diff --git a/src/libraries/System.Security.Cryptography.Pkcs/tests/CryptographicAttributeObjectCollectionTests.cs b/src/libraries/System.Security.Cryptography.Pkcs/tests/CryptographicAttributeObjectCollectionTests.cs
index 18a4444a1c5c95..68e6f5ef062949 100644
--- a/src/libraries/System.Security.Cryptography.Pkcs/tests/CryptographicAttributeObjectCollectionTests.cs
+++ b/src/libraries/System.Security.Cryptography.Pkcs/tests/CryptographicAttributeObjectCollectionTests.cs
@@ -164,7 +164,7 @@ public static void CopyExceptions()
if (PlatformDetection.IsNonZeroLowerBoundArraySupported)
{
// Array has non-zero lower bound
-#pragma warning disable IL3050
+#pragma warning disable IL3050 // Creating multi-dimensional arrays is AOT safe, only SzArrays are problem
Array array = Array.CreateInstance(typeof(object), new int[] { 10 }, new int[] { 10 });
#pragma warning restore IL3050
Assert.Throws(() => ic.CopyTo(array, 0));
diff --git a/src/libraries/System.Security.Cryptography.Pkcs/tests/RecipientInfoCollectionTests.cs b/src/libraries/System.Security.Cryptography.Pkcs/tests/RecipientInfoCollectionTests.cs
index d1e82818ccef97..4bbeb912b61d66 100644
--- a/src/libraries/System.Security.Cryptography.Pkcs/tests/RecipientInfoCollectionTests.cs
+++ b/src/libraries/System.Security.Cryptography.Pkcs/tests/RecipientInfoCollectionTests.cs
@@ -142,7 +142,7 @@ public static void TestExplicitCopyToExceptions()
if (PlatformDetection.IsNonZeroLowerBoundArraySupported)
{
// Array has non-zero lower bound
-#pragma warning disable IL3050
+#pragma warning disable IL3050 // Creating multi-dimensional arrays is AOT safe, only SzArrays are problem
Array array = Array.CreateInstance(typeof(object), new int[] { 10 }, new int[] { 10 });
#pragma warning restore IL3050
Assert.Throws(() => col.CopyTo(array, 0));
diff --git a/src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/JsonSourceGeneratorIncrementalTests.cs b/src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/JsonSourceGeneratorIncrementalTests.cs
index 6c686240c9e00d..482d1dda837aaf 100644
--- a/src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/JsonSourceGeneratorIncrementalTests.cs
+++ b/src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/JsonSourceGeneratorIncrementalTests.cs
@@ -32,7 +32,9 @@ public static void CompilingTheSameSourceResultsInEqualModels(Func
ContextGenerationSpec ctx2 = result2.ContextGenerationSpecs[i];
Assert.NotSame(ctx1, ctx2);
+#pragma warning disable IL2026 // Checks structural equality using reflection
GeneratorTestHelpers.AssertStructurallyEqual(ctx1, ctx2);
+#pragma warning restore IL2026
Assert.Equal(ctx1, ctx2);
Assert.Equal(ctx1.GetHashCode(), ctx2.GetHashCode());
@@ -89,7 +91,9 @@ public partial class JsonContext : JsonSerializerContext { }
ContextGenerationSpec ctx2 = result2.ContextGenerationSpecs[0];
Assert.NotSame(ctx1, ctx2);
+#pragma warning disable IL2026 // Checks structural equality using reflection
GeneratorTestHelpers.AssertStructurallyEqual(ctx1, ctx2);
+#pragma warning restore IL2026
Assert.Equal(ctx1, ctx2);
Assert.Equal(ctx1.GetHashCode(), ctx2.GetHashCode());
@@ -176,7 +180,7 @@ void Visit(object? node)
return;
}
-#pragma warning disable IL2075
+#pragma warning disable IL2075 // https://github.com/dotnet/runtime/issues/126862
foreach (FieldInfo field in type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
#pragma warning restore IL2075
{
From f5c77cc5e393aa664705717150767ece31306ca2 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Thu, 21 May 2026 05:30:13 +0000
Subject: [PATCH 6/8] Clean up Quic analyzer annotations
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/087bc9c5-a2a7-4eea-becd-4a9625ddce15
Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
---
.../tests/FunctionalTests/MsQuicInteropTests.cs | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/src/libraries/System.Net.Quic/tests/FunctionalTests/MsQuicInteropTests.cs b/src/libraries/System.Net.Quic/tests/FunctionalTests/MsQuicInteropTests.cs
index 3fd98d50b13097..3acc704c903ca2 100644
--- a/src/libraries/System.Net.Quic/tests/FunctionalTests/MsQuicInteropTests.cs
+++ b/src/libraries/System.Net.Quic/tests/FunctionalTests/MsQuicInteropTests.cs
@@ -18,11 +18,16 @@ namespace System.Net.Quic.Tests
{
public class MsQuicInteropTests
{
+ private const DynamicallyAccessedMemberTypes FieldsAndProperties =
+ DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields |
+ DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.NonPublicProperties;
+ private const BindingFlags InstanceMembers = BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public;
+
private static MemberInfo[] GetMembers<
- [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields | DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.NonPublicProperties)] T>()
+ [DynamicallyAccessedMembers(FieldsAndProperties)] T>()
{
- var members = typeof(T).GetFields(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public).Cast()
- .Concat(typeof(T).GetProperties(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public).Where(property => property.GetSetMethod() is not null))
+ var members = typeof(T).GetFields(InstanceMembers).Cast()
+ .Concat(typeof(T).GetProperties(InstanceMembers).Where(property => property.GetSetMethod() is not null))
.ToArray();
Assert.NotEmpty(members);
From ef691cd0065961c22a0265fb7e427912316c5aae Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?=
Date: Thu, 21 May 2026 15:14:46 +0900
Subject: [PATCH 7/8] Apply suggestions from code review
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Co-authored-by: Michal Strehovský
---
.../tests/SourceGenerationTests/GeneratorTests.Incremental.cs | 2 +-
.../tests/FunctionalTests/MsQuicInteropTests.cs | 2 +-
.../tests/System.Buffers.Tests/ArrayPool/CollectionTests.cs | 2 +-
.../JsonSourceGeneratorIncrementalTests.cs | 4 ++--
4 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/GeneratorTests.Incremental.cs b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/GeneratorTests.Incremental.cs
index 30d533cd4e5ad6..040118111effee 100644
--- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/GeneratorTests.Incremental.cs
+++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/GeneratorTests.Incremental.cs
@@ -22,7 +22,7 @@ public async Task CompilingTheSameSourceResultsInEqualModels()
SourceGenerationSpec spec2 = (await new ConfigBindingGenTestDriver().RunGeneratorAndUpdateCompilation(BindCallSampleCode)).GenerationSpec;
Assert.NotSame(spec1, spec2);
-#pragma warning disable IL2026 // Checks structural equality using reflection
+#pragma warning disable IL2026 // https://github.com/dotnet/runtime/issues/126862
GeneratorTestHelpers.AssertStructurallyEqual(spec1, spec2);
#pragma warning restore IL2026
diff --git a/src/libraries/System.Net.Quic/tests/FunctionalTests/MsQuicInteropTests.cs b/src/libraries/System.Net.Quic/tests/FunctionalTests/MsQuicInteropTests.cs
index 3acc704c903ca2..4f9f7d8c083459 100644
--- a/src/libraries/System.Net.Quic/tests/FunctionalTests/MsQuicInteropTests.cs
+++ b/src/libraries/System.Net.Quic/tests/FunctionalTests/MsQuicInteropTests.cs
@@ -68,7 +68,7 @@ public void QuicSettings_Equals_RespectsAllMembers()
{
// copy and box the instance because reflection methods take a reference type arg
object boxed = settings;
-#pragma warning disable IL2026 // Resets members using reflection
+#pragma warning disable IL2026 // https://github.com/dotnet/runtime/issues/126862
ResetMember(member, boxed);
#pragma warning restore IL2026
Assert.False(settings.Equals((QUIC_SETTINGS)boxed), $"Member {member.Name} is not compared.");
diff --git a/src/libraries/System.Runtime/tests/System.Buffers.Tests/ArrayPool/CollectionTests.cs b/src/libraries/System.Runtime/tests/System.Buffers.Tests/ArrayPool/CollectionTests.cs
index 4e1e09cb1f59b7..528d733d026640 100644
--- a/src/libraries/System.Runtime/tests/System.Buffers.Tests/ArrayPool/CollectionTests.cs
+++ b/src/libraries/System.Runtime/tests/System.Buffers.Tests/ArrayPool/CollectionTests.cs
@@ -92,7 +92,7 @@ public unsafe void ThreadLocalIsCollectedUnderHighPressure()
const int AllocSize = 1024 * 1024 * 64;
int PageSize = Environment.SystemPageSize;
-#pragma warning disable IL2075 // This private reflection is broken since .NET 6
+#pragma warning disable IL2075 // This private reflection is broken since .NET 6: https://github.com/dotnet/runtime/issues/128431
var pressureMethod = ArrayPool.Shared.GetType().GetMethod("GetMemoryPressure", BindingFlags.Static | BindingFlags.NonPublic);
#pragma warning restore IL2075
do
diff --git a/src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/JsonSourceGeneratorIncrementalTests.cs b/src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/JsonSourceGeneratorIncrementalTests.cs
index 482d1dda837aaf..970cb99960b1a3 100644
--- a/src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/JsonSourceGeneratorIncrementalTests.cs
+++ b/src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/JsonSourceGeneratorIncrementalTests.cs
@@ -32,7 +32,7 @@ public static void CompilingTheSameSourceResultsInEqualModels(Func
ContextGenerationSpec ctx2 = result2.ContextGenerationSpecs[i];
Assert.NotSame(ctx1, ctx2);
-#pragma warning disable IL2026 // Checks structural equality using reflection
+#pragma warning disable IL2026 // https://github.com/dotnet/runtime/issues/126862
GeneratorTestHelpers.AssertStructurallyEqual(ctx1, ctx2);
#pragma warning restore IL2026
@@ -91,7 +91,7 @@ public partial class JsonContext : JsonSerializerContext { }
ContextGenerationSpec ctx2 = result2.ContextGenerationSpecs[0];
Assert.NotSame(ctx1, ctx2);
-#pragma warning disable IL2026 // Checks structural equality using reflection
+#pragma warning disable IL2026 // https://github.com/dotnet/runtime/issues/126862
GeneratorTestHelpers.AssertStructurallyEqual(ctx1, ctx2);
#pragma warning restore IL2026
From fa2c19f157493bcd7e8c19aa575b46a7c51d55fb Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Thu, 21 May 2026 07:46:03 +0000
Subject: [PATCH 8/8] Fix analyzer warnings in Windows library tests
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/5e49e977-7ef9-4b3f-ba25-f076d020cb7e
Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
---
.../System/DirectoryServices/DirectoryServicesTests.cs | 8 +++++---
.../tests/System/Management/ManagementObjectTests.cs | 5 +++++
2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/src/libraries/System.DirectoryServices/tests/System/DirectoryServices/DirectoryServicesTests.cs b/src/libraries/System.DirectoryServices/tests/System/DirectoryServices/DirectoryServicesTests.cs
index 5cf652ca1b6b28..f4a256257ffa18 100644
--- a/src/libraries/System.DirectoryServices/tests/System/DirectoryServices/DirectoryServicesTests.cs
+++ b/src/libraries/System.DirectoryServices/tests/System/DirectoryServices/DirectoryServicesTests.cs
@@ -1,12 +1,12 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System.Runtime.InteropServices;
-using System.Collections.Generic;
using System.Collections;
+using System.Collections.Generic;
+using System.Reflection;
+using System.Runtime.InteropServices;
using Xunit;
using Xunit.Sdk;
-using System.Reflection;
namespace System.DirectoryServices.Tests
{
@@ -18,7 +18,9 @@ public partial class DirectoryServicesTests
[Fact]
public void TestGetAllTypes()
{
+#pragma warning disable IL2026 // Test validates Assembly.GetTypes in an untrimmed test build.
Type[] allTypes = typeof(DirectoryEntry).Assembly.GetTypes();
+#pragma warning restore IL2026
Assert.Contains(typeof(DirectoryEntry), allTypes);
}
diff --git a/src/libraries/System.Management/tests/System/Management/ManagementObjectTests.cs b/src/libraries/System.Management/tests/System/Management/ManagementObjectTests.cs
index ccf8154335a87d..490d31fd303943 100644
--- a/src/libraries/System.Management/tests/System/Management/ManagementObjectTests.cs
+++ b/src/libraries/System.Management/tests/System/Management/ManagementObjectTests.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using Microsoft.DotNet.XUnitExtensions;
@@ -105,6 +106,10 @@ public void Invoke_Instance_And_Static_Method_Win32_Process()
[ConditionalFact(typeof(WmiTestHelper), nameof(WmiTestHelper.IsWmiSupported))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/34689", TestPlatforms.Windows, TargetFrameworkMonikers.Netcoreapp, TestRuntimes.Mono)]
[OuterLoop]
+#if NET
+ [RequiresDynamicCode("BinaryFormatter serialization uses dynamic code generation")]
+ [RequiresUnreferencedCode("BinaryFormatter serialization is not trim compatible")]
+#endif
public void Serialize_ManagementException()
{
try