You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Write-Host renders an [xml] or [XmlElement] instance as an empty line. #24508
Write-Host ([xml] '<OhElement>Where art thou?</OhElement>').DocumentElement
Note: The problem may come down to the base class, System.Xml.XmlNode, implementing IEnumerable, and Write-Host not only enumerating the given instance itself, but doing so recursively, down to the leaf elements that by definition have nothing to enumerate. As argued below, no enumeration should take place at all.
Expected behavior
OhElement
i.e., the name of the element, as if you had applied .ToString() to the instance.
Note that even though such instances technically implement IEnumerable, for consistency with pipeline enumeration behavior I expect them not to be enumerated.
I suspect that the bug is related to the fact that they are enumerated.
Actual behavior
(An empty line prints.)
Error details
No response
Environment data
PowerShell 7.5.0-preview.5 (problem dates back to Windows PowerShell)
When piping to Write-Host, the XmlElement object is wrapped into a PSObject, and falls to the PSObject.ToString call.
But for Write-Host ([xml] '<OhElement>Where art thou?</OhElement>').DocumentElement, the XmlElement object is NOT wrapped to PSObject, so it's processed as an enumerable. XmlNode shouldn't be considered as enumerable.
Activity
SteveL-MSFT commentedon Dec 12, 2024
does the right thing, so it's definitely an issue during enumeration
daxian-dbw commentedon Dec 12, 2024
When piping to
Write-Host, theXmlElementobject is wrapped into aPSObject, and falls to thePSObject.ToStringcall.But for
Write-Host ([xml] '<OhElement>Where art thou?</OhElement>').DocumentElement, theXmlElementobject is NOT wrapped toPSObject, so it's processed as an enumerable.XmlNodeshouldn't be considered as enumerable.daxian-dbw commentedon Dec 12, 2024
Write-HostrendersIDictionaryinconsistently depending on how the value is passed in. This is tracked by #24671.microsoft-github-policy-service commentedon Dec 13, 2024
📣 Hey Michael Klement (@mklement0), how did we do? We would love to hear your feedback with the link below! 🗣️
🔗 https://aka.ms/PSRepoFeedback