Fix Serialize_ManagementException by referencing functional BinaryFormatter - #132382
Open
jeffhandley wants to merge 1 commit into
Open
Fix Serialize_ManagementException by referencing functional BinaryFormatter#132382jeffhandley wants to merge 1 commit into
jeffhandley wants to merge 1 commit into
Conversation
…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>
|
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. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes System.Management.Tests’ Serialize_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
IsWmiAndBinaryFormatterSupportedgate and updatedSerialize_ManagementException’s[ConditionalFact]to use it. - Updated
System.Management.Tests.csproj(non-NetFx) toProjectReferencetheNetCoreAppMinimumbuild ofSystem.Runtime.Serialization.Formatters, withPrivate="true"andSetTargetFramework=....
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. |
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-management |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The in-box BinaryFormatter has thrown
PlatformNotSupportedExceptionsince .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.TestsandSystem.Runtime.Tests): take a privateProjectReferenceon theNetCoreAppMinimumbuild ofSystem.Runtime.Serialization.Formatters, which has a functional implementation, and gate the test onPlatformDetection.IsBinaryFormatterSupportedso it skips where the feature is unavailable (source-build, NativeAOT, mobile, browser).ManagementExceptionremains[Serializable]with aGetObjectDataoverride that deliberately omitsErrorInformation, 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.IsWmiSupportedgates on Arm32, not ARM64, so these tests really do execute here):build.cmd clr+libs -rc release— exit 0PlatformNotSupportedExceptionfrom the issueVerified 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:
Private="true"FileNotFoundExceptionforVersion=11.0.0.0SetTargetFrameworkPlatformNotSupportedExceptionIsBinaryFormatterSupportedgateNetCoreAppMinimumcollapses ontoNetCoreAppCurrentand the reference resolves back to the throwing buildPrivate="true"is needed becauseeng/references.targetsdefaultsPrivatetofalsefor anyProjectReferencewhose filename appears in@(NetCoreAppLibrary), which includesSystem.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.