Steps to reproduce
Insert the following commands
$a = @{Key = "Test"}
$a.Parent = $a
$a | ConvertTo-Xml -As String
Expected behavior
I would expect an XML string with the output limited to the default depth of 3:
<Property Name="Key" Type="System.String">Key</Property>
<Property Name="Value" Type="System.String">Test</Property>
<Property Name="Key" Type="System.String">Parent</Property>
<Property Name="Value" Type="System.Collections.Hashtable">
<Property Name="Key" Type="System.String">Key</Property>
<Property Name="Value" Type="System.String">Test</Property>
<Property Name="Key" Type="System.String">Parent</Property>
<Property Name="Value" Type="System.Collections.Hashtable">
<Property Name="Key" Type="System.String">Key</Property>
<Property Name="Value" Type="System.String">Test</Property>
<Property Name="Key" Type="System.String">Parent</Property>
<Property Name="Value" Type="System.String">end</Property>
</Property>
</Property>
Actual behavior
Instead, it first shows:
Process is terminating due to StackOverflowException.
And a few seconds later the whole shell is terminated.
- Note: the same issue appears when the depth is explicitly given (e.g.
-Depth 3)
PowerShell Windows
A similar issue exist in PowerShell Windows (5.1) which reports:
ConvertTo-Xml : Stream was too long.
At line:1 char:6
- $a | ConvertTo-Xml
-
- CategoryInfo : NotSpecified: (:) [ConvertTo-Xml], IOException
- FullyQualifiedErrorId : System.IO.IOException,Microsoft.PowerShell.Commands.ConvertToXmlCommand
But does not crash.
Environment data
Name Value
---- -----
PSVersion 6.0.2
PSEdition Core
GitCommitId v6.0.2
OS Microsoft Windows 10.0.17134
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
ConvertTo-Xml version: 3.1.0.0
Steps to reproduce
Insert the following commands
Expected behavior
I would expect an XML string with the output limited to the default depth of 3:
Actual behavior
Instead, it first shows:
And a few seconds later the whole shell is terminated.
-Depth 3)PowerShell Windows
A similar issue exist in PowerShell Windows (5.1) which reports:
But does not crash.
Environment data