Skip to content

Fix Serialize_ManagementException by referencing functional BinaryFormatter - #132382

Open
jeffhandley wants to merge 1 commit into
mainfrom
jeffhandley/fix-binaryformatter-management-test
Open

Fix Serialize_ManagementException by referencing functional BinaryFormatter#132382
jeffhandley wants to merge 1 commit into
mainfrom
jeffhandley/fix-binaryformatter-management-test

Conversation

@jeffhandley

Copy link
Copy Markdown
Member

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 #119631

Validation

Ran locally on Windows 11 ARM64 (WmiTestHelper.IsWmiSupported gates on Arm32, not ARM64, so these tests really do execute here):

  • Baseline build.cmd clr+libs -rc release — exit 0
  • Both TFMs build with 0 warnings, 0 errors
  • Target test, net11.0-windows, OuterLoop — Total 1, Failed 0
  • Control with the csproj change reverted — Failed 1, with the exact PlatformNotSupportedException from the issue
  • Target test, net481, OuterLoop — Total 1, Failed 0
  • Full suite, net11.0-windows — 36 total, 0 failed, 10 skipped
  • Full suite, net481 — 35 total, 0 failed, 10 skipped

Verified the functional 157,184 B assembly is copied to the test output and that the generated runtimeconfig carries "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": true.

Why each attribute is required

Each was confirmed empirically by removing it and observing the failure:

Missing Lands in output Failure
Private="true" nothing FileNotFoundException for Version=11.0.0.0
SetTargetFramework 70,144 B stub PlatformNotSupportedException
the IsBinaryFormatterSupported gate n/a breaks source-build, where NetCoreAppMinimum collapses onto NetCoreAppCurrent and the reference resolves back to the throwing build
nothing (this PR) 157,184 B functional passes

Private="true" is needed because eng/references.targets defaults Private to false for any ProjectReference whose filename appears in @(NetCoreAppLibrary), which includes System.Runtime.Serialization.Formatters. That default is normally right, but here we deliberately want a different build than the one in the shared framework.

Note

This pull request was authored by GitHub Copilot.

…matter

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 #119631

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings August 17, 2026 04:01
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 fixes System.Management.TestsSerialize_ManagementException outer-loop test on modern .NET by ensuring it only runs when WMI and BinaryFormatter are available, and by referencing a functional System.Runtime.Serialization.Formatters build for the .NET (non-NetFx) target.

Changes:

  • Added a combined IsWmiAndBinaryFormatterSupported gate and updated Serialize_ManagementException’s [ConditionalFact] to use it.
  • Updated System.Management.Tests.csproj (non-NetFx) to ProjectReference the NetCoreAppMinimum build of System.Runtime.Serialization.Formatters, with Private="true" and SetTargetFramework=....

Reviewed changes

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

File Description
src/libraries/System.Management/tests/System/Management/ManagementObjectTests.cs Gates Serialize_ManagementException on both WMI and BinaryFormatter availability via a combined conditional.
src/libraries/System.Management/tests/System.Management.Tests.csproj References the functional NetCoreAppMinimum System.Runtime.Serialization.Formatters and ensures it’s copied locally for the test run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-system-management
See info in area-owners.md if you want to be subscribed.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

System.PlatformNotSupportedException : BinaryFormatter serialization and deserialization have been removed.

2 participants