Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/System.Management.Automation/engine/serialization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1482,6 +1482,24 @@ int depth
_writer.WriteEndElement();
}

private static PSObject GetRemotingSerializationTarget(PSObject source)
{
PSObject target = source.Copy();

// Keep remoting-only notes local to the serialization wrapper, rather
// than writing them to the base object's resurrection table.
target.InstanceMembers = new PSMemberInfoInternalCollection<PSMemberInfo>();
foreach (PSMemberInfo member in source.InstanceMembers)
{
if (!member.IsHidden)
{
target.InstanceMembers.Add(member.Copy());
}
}
Comment on lines +1492 to +1498
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 16245c451: the remoting serialization wrapper now adds member.Copy() to target.InstanceMembers, so the wrapper owns independent member instances.


return target;
}

private void HandleComplexTypePSObject
(
object source,
Expand Down Expand Up @@ -1514,6 +1532,7 @@ int depth
ErrorRecord errorRecord = mshSource.ImmediateBaseObject as ErrorRecord;
if (errorRecord != null)
{
mshSource = GetRemotingSerializationTarget(mshSource);
errorRecord.ToPSObjectForRemoting(mshSource);
isErrorRecord = true;
break;
Expand All @@ -1522,6 +1541,7 @@ int depth
InformationalRecord informationalRecord = mshSource.ImmediateBaseObject as InformationalRecord;
if (informationalRecord != null)
{
mshSource = GetRemotingSerializationTarget(mshSource);
informationalRecord.ToPSObjectForRemoting(mshSource);
isInformationalRecord = true;
break;
Comment on lines 1541 to 1547
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 16245c451: added matching Export-Clixml and ConvertTo-CliXml regression coverage for InformationRecord inputs.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,26 @@ Describe "CliXml test" -Tags "CI" {
$this.testFile = $file
}
}

function Get-ExtendedMemberNames {
param([object] $InputObject)

@($InputObject | Get-Member -View Extended | Select-Object -ExpandProperty Name)
}

function New-TestErrorRecord {
try {
Write-Error foo -ErrorAction Stop
}
catch {
$_
}
}

function New-TestInformationRecord {
Write-Information foo -Tags test -InformationAction Continue -InformationVariable informationRecord 6>$null
$informationRecord[0]
}
}

AfterAll {
Expand Down Expand Up @@ -184,6 +204,28 @@ Describe "CliXml test" -Tags "CI" {
$cred.UserName | Should -BeExactly "Foo"
$cred.Password | Should -BeOfType System.Security.SecureString
}

It "does not add remoting serialization members to ErrorRecord input" {
$filePath = Join-Path $subFilePath 'error.xml'
$errorRecord = New-TestErrorRecord
$before = Get-ExtendedMemberNames $errorRecord

$errorRecord | Export-Clixml -Path $filePath

$after = Get-ExtendedMemberNames $errorRecord
@($after | Where-Object { $_ -notin $before }) | Should -BeNullOrEmpty
}

It "does not add remoting serialization members to InformationRecord input" {
$filePath = Join-Path $subFilePath 'information.xml'
$informationRecord = New-TestInformationRecord
$before = Get-ExtendedMemberNames $informationRecord

$informationRecord | Export-Clixml -Path $filePath

$after = Get-ExtendedMemberNames $informationRecord
@($after | Where-Object { $_ -notin $before }) | Should -BeNullOrEmpty
}
}

Context "ConvertTo-CliXml"{
Expand Down Expand Up @@ -232,6 +274,26 @@ Describe "CliXml test" -Tags "CI" {

$isExisted | Should -BeTrue
}

It "does not add remoting serialization members to ErrorRecord input" {
$errorRecord = New-TestErrorRecord
$before = Get-ExtendedMemberNames $errorRecord

$null = $errorRecord | ConvertTo-CliXml

$after = Get-ExtendedMemberNames $errorRecord
@($after | Where-Object { $_ -notin $before }) | Should -BeNullOrEmpty
}

It "does not add remoting serialization members to InformationRecord input" {
$informationRecord = New-TestInformationRecord
$before = Get-ExtendedMemberNames $informationRecord

$null = $informationRecord | ConvertTo-CliXml

$after = Get-ExtendedMemberNames $informationRecord
@($after | Where-Object { $_ -notin $before }) | Should -BeNullOrEmpty
}
}

Context "ConvertFrom-CliXml" {
Expand Down