From 8c8583f21ffa31166e1e9a41db1aa359d9ae6a9f Mon Sep 17 00:00:00 2001 From: Jeff Handley Date: Sun, 16 Aug 2026 19:56:33 -0700 Subject: [PATCH] Fix Serialize_ManagementException by referencing functional BinaryFormatter The in-box BinaryFormatter has thrown PlatformNotSupportedException since .NET 9, so this OuterLoop, WMI-gated test has been failing whenever it actually runs. Follow the established pattern used by nine other libraries test projects (for example Microsoft.Extensions.Hosting.Unit.Tests and System.Runtime.Tests): take a private ProjectReference on the NetCoreAppMinimum build of System.Runtime.Serialization.Formatters, which has a functional implementation, and gate the test on PlatformDetection.IsBinaryFormatterSupported so it skips where the feature is unavailable (source-build, NativeAOT, mobile, browser). ManagementException remains [Serializable] with a GetObjectData override that deliberately omits ErrorInformation, so this keeps real coverage of shipping product behavior on both net11.0 and net481 instead of deleting it. Fixes dotnet/runtime#119631 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .../tests/System.Management.Tests.csproj | 8 ++++++++ .../tests/System/Management/ManagementObjectTests.cs | 4 +++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/libraries/System.Management/tests/System.Management.Tests.csproj b/src/libraries/System.Management/tests/System.Management.Tests.csproj index ad44bb1733676b..178ea7d9779a3b 100644 --- a/src/libraries/System.Management/tests/System.Management.Tests.csproj +++ b/src/libraries/System.Management/tests/System.Management.Tests.csproj @@ -29,4 +29,12 @@ + + + + \ No newline at end of file diff --git a/src/libraries/System.Management/tests/System/Management/ManagementObjectTests.cs b/src/libraries/System.Management/tests/System/Management/ManagementObjectTests.cs index 490d31fd303943..666c190ed5b890 100644 --- a/src/libraries/System.Management/tests/System/Management/ManagementObjectTests.cs +++ b/src/libraries/System.Management/tests/System/Management/ManagementObjectTests.cs @@ -13,6 +13,8 @@ namespace System.Management.Tests { public class ManagementObjectTests { + private static bool IsWmiAndBinaryFormatterSupported => WmiTestHelper.IsWmiSupported && PlatformDetection.IsBinaryFormatterSupported; + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsWindowsNanoServer))] public void PlatformNotSupportedException_On_Nano() { @@ -103,7 +105,7 @@ public void Invoke_Instance_And_Static_Method_Win32_Process() }, maxAttempts: 10, retryWhen: e => e is XunitException); } - [ConditionalFact(typeof(WmiTestHelper), nameof(WmiTestHelper.IsWmiSupported))] + [ConditionalFact(typeof(ManagementObjectTests), nameof(IsWmiAndBinaryFormatterSupported))] [ActiveIssue("https://github.com/dotnet/runtime/issues/34689", TestPlatforms.Windows, TargetFrameworkMonikers.Netcoreapp, TestRuntimes.Mono)] [OuterLoop] #if NET