◐ Shell
clean mode source ↗

Avoid decorating ErrorRecord during CliXml serialization by KirtiRamchandani · Pull Request #27528 · PowerShell/PowerShell

PR Summary

Fixes #25854.

ConvertTo-CliXml and Export-CliXml serialize ErrorRecord instances by adding remoting-specific note properties such as ErrorCategory_Activity and InvocationInfo. The serializer was adding those properties to the caller's PSObject wrapper, which caused the original ErrorRecord to gain serialization-only extended members after serialization completed.

This change serializes remoting records through a wrapper with local instance members, preserving the generated CliXml fields without decorating the caller's input object.

PR Context

PSObject.Copy() alone still shares the base object's resurrection-table key, so note properties added to the copy are visible on wrappers around the same base object. The new helper resets the serialization wrapper's instance-member collection before adding remoting-only properties, while preserving existing visible instance members for serialization.

The same path is used for informational records, so the isolation is applied there too.

PR Checklist

  • Tests pass

Tests

  • Reproduced before fix: serializing an ErrorRecord increased extended members from 1 to 13 and added ErrorCategory_*, InvocationInfo, SerializeExtendedInfo, and related serialization notes.
  • Added regression coverage for both Export-Clixml and ConvertTo-CliXml.
  • Start-PSBuild -Configuration Debug -SMAOnly
  • Manual verification after fix: ConvertTo-CliXml and Export-Clixml added no extended members to the original ErrorRecord.
  • Manual verification after fix: generated CliXml still contains ErrorCategory_Category and ConvertFrom-CliXml round-trips the error information.
  • Start-PSPester -Path .\test\powershell\Modules\Microsoft.PowerShell.Utility\clixml.tests.ps1 -Terse -ThrowOnFailure -SkipTestToolBuild -BinDir <publish> (19 passed)
  • git diff --check (line-ending warning only)