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.Members.Add(member);
}
}
Comment on lines +1492 to +1498

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ Describe "CliXml test" -Tags "CI" {
$this.testFile = $file
}
}

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

@($InputObject | Get-Member -View Extended | Select-Object -ExpandProperty Name)
}
Comment on lines +39 to +43
}

AfterAll {
Expand Down Expand Up @@ -184,6 +190,18 @@ 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'
Write-Error foo 2>$null
$errorRecord = $Error[0]
$before = Get-ExtendedMemberName $errorRecord
Comment on lines +195 to +198

$errorRecord | Export-Clixml -Path $filePath

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

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

$isExisted | Should -BeTrue
}

It "does not add remoting serialization members to ErrorRecord input" {
Write-Error foo 2>$null
$errorRecord = $Error[0]
$before = Get-ExtendedMemberName $errorRecord
Comment on lines +255 to +257

$null = $errorRecord | ConvertTo-CliXml

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

Context "ConvertFrom-CliXml" {
Expand Down