Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

XML nodes are too picky about setting values #2459

Copy link
Copy link
@Jaykul

Description

@Jaykul
Issue body actions

When setting an XML node content, PowerShell doesn't correctly unwrap PSObject strings.

For instance: Join-Path obviously outputs strings, but it outputs them wrapped in PSObjects

Steps to reproduce

[xml]$x  = "<root><path/></root>"
$x.root.path = Join-Path C:\ Windows

Expected behavior

$x.root.path is an XML Node with string content "C:\Windows"

Actual behavior

A SetValueException is thrown:

Cannot set "path" because only strings can be used as values to set XmlNode properties.
At line:2 char:1
+ $x.root.path = Join-Path C:\ Windows
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], SetValueException
    + FullyQualifiedErrorId : XmlNodeSetShouldBeAString

Environment data

> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.14393.206
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14393.206
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Workaround

Either of the following would work, but should not be necessary:

$x.root.path = (Join-Path C:\ Windows).PSObject.BaseObject
$x.root.path = (Join-Path C:\ Windows).ToString()
Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    Resolution-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-Enginecore PowerShell engine, interpreter, and runtimecore PowerShell engine, interpreter, and runtime

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.