-
Notifications
You must be signed in to change notification settings - Fork 8.2k
ConvertTo-Xml fails with nested custom objects: omits closing </Objects> tag #8308
Copy link
Copy link
Closed
Labels
Issue-BugIssue has been identified as a bug in the productIssue has been identified as a bug in the productResolution-FixedThe issue is fixed.The issue is fixed.Up-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility modulecmdlets in the Microsoft.PowerShell.Utility module
Description
See repro below.
As an aside (that will probably become a docs issue): What is the purpose of ConvertTo-Xml? The docs suggest that it is the in-memory counterpart to Export-Clixml, however:
- It produces different XML representations,
- which, if saved to a file, cannot be re-imported with
Import-Clixml
Steps to reproduce
[pscustomobject] @{ a = [pscustomobject] @{ aa=11; bb=22 } } | ConvertTo-XmlExpected behavior
Should output an [xml] instance that is the serialization of the custom object.
Actual behavior
The following error occurs:
ConvertTo-Xml : Unexpected end of file has occurred. The following elements are not closed: Objects.
-
If you use
-As String, you don't get an error, but the XML string output too is missing the closing</Objects>tag. -
Removing the 2nd property (
bb) from the nested custom object makes the problem go away. -
Using
[hashtable]instances instead of[pscustomobject]s makes the problem go away. -
Export-Clixmldoes not exhibit the problem.
Environment data
PowerShell Core 6.2.0-preview.1 on macOS 10.14.1
PowerShell Core 6.2.0-preview.1 on Ubuntu 16.04.5 LTS
PowerShell Core 6.2.0-preview.1 on Microsoft Windows 10 Pro (64-bit; Version 1803, OS Build: 17134.345)
Windows PowerShell v5.1.17134.228 on Microsoft Windows 10 Pro (64-bit; Version 1803, OS Build: 17134.345)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Issue-BugIssue has been identified as a bug in the productIssue has been identified as a bug in the productResolution-FixedThe issue is fixed.The issue is fixed.Up-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility modulecmdlets in the Microsoft.PowerShell.Utility module