Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - tee-object bug

Reply
 
Old 12-19-2007   #1 (permalink)
Karl Prosser[MVP]


 
 

tee-object bug

[xml]$a = "<hello>there</hello>"
$a | tee-object -variable test

gives

Exception retrieving string: "Cannot find an overload for "XmlNode" and
the argument count: "3"."

... anybody dare to suggest the cause of this bug. Maybe a side effect of
the powershell adapter. and an assumption tee-object makes?

-Karl

My System SpecsSystem Spec
Old 12-19-2007   #2 (permalink)
Shay Levi


 
 

Re: tee-object bug


Shouldn't you add a reference to $test or I'm missing something?

PS > $test=""
PS > [xml]$a = "<hello>there</hello>"
PS > $a | tee-object -variable [ref]test

hello
-----
there


The help for tee-object:

-variable <string>
Assigns a reference to the input objects to the specified variable.



-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Hebrew weblog: http://blogs.microsoft.co.il/blogs/scriptfanatic


Quote:

> [xml]$a = "<hello>there</hello>"
> $a | tee-object -variable test
> gives
>
> Exception retrieving string: "Cannot find an overload for "XmlNode"
> and the argument count: "3"."
>
> .. anybody dare to suggest the cause of this bug. Maybe a side effect
> of the powershell adapter. and an assumption tee-object makes?
>
> -Karl
>

My System SpecsSystem Spec
Old 12-19-2007   #3 (permalink)
Steven Hystad


 
 

Re: tee-object bug

At first glance it would appear to me that Tee-Object is trying to copy the
XmlDocument by creating a new XmlNode. However, that would be impossible as
XmlNode is abstract. It would be more rational to try to create a new
XmlDocument.

After throwing the exception into my errordialog script I see that it is
actually trying to dynamically invoke a method.
A fast search in .NET Reflector found a static "XmlNode" method.

Microsoft.PowerShell.ToStringCodeMethods.XmlNode(PSObject) as String
within System.Management.Automation.dll

There were no other overloads visible.

Looking at the stack trace I see it being called by
PSObject.ToString(String, IFormatProvider).

$a.ToString($null, $null) will give the same error.

It seems to be that PSObject.ToString(String, IFormatProvider) can not
process correctly when it is overridden by the XmlNode code method.

PSObject.ToString is being called by the Set-Variable cmdlet so I don't see
any easy way around this bug.

"Karl Prosser[MVP]" <karl@xxxxxx_o_w_e_r_s_h_e_l_l.com> wrote in message
news:%23BmlLChQIHA.4584@xxxxxx
Quote:

> [xml]$a = "<hello>there</hello>"
> $a | tee-object -variable test
>
> gives
>
> Exception retrieving string: "Cannot find an overload for "XmlNode" and
> the argument count: "3"."
>
> .. anybody dare to suggest the cause of this bug. Maybe a side effect of
> the powershell adapter. and an assumption tee-object makes?
>
> -Karl
My System SpecsSystem Spec
Old 12-19-2007   #4 (permalink)
Kiron


 
 

Re: tee-object bug

The problem occurs when value is piped to sv or pass to sv by tee.

# no problem
rv test -ea 0
sv test ([Xml]"<hello>there</hello>")
$test

# problen when assigned by piped value
rv test -ea 0
[Xml]"<hello>there</hello>" | sv test
$test

rv test -ea 0
[Xml]"<hello>there</hello>" | % {sv test ($_)}
$test

# problem because tee calls sv
rv test -ea 0
tee -va test -input ([Xml]"<hello>there</hello>")
$test

rv test -ea 0
[Xml]"<hello>there</hello>" | tee -va test
$test

---
somebody
My System SpecsSystem Spec
Old 12-19-2007   #5 (permalink)
Oisin Grehan


 
 

Re: tee-object bug

On Dec 19, 2:57 am, Shay Levi <n...@xxxxxx> wrote:
Quote:

> Shouldn't you add a reference to $test or I'm missing something?
>
> PS > $test=""
> PS > [xml]$a = "<hello>there</hello>"
> PS > $a | tee-object -variable [ref]test
>
> hello
> -----
> there
>
> The help for tee-object:
>
> -variable <string>
> Assigns a reference to the input objects to the specified variable.
>
> -----
> Shay Levi
> $cript Fanatichttp://scriptolog.blogspot.com
> Hebrew weblog:http://blogs.microsoft.co.il/blogs/scriptfanatic
>
>
>
Quote:

> > [xml]$a = "<hello>there</hello>"
> > $a | tee-object -variable test
> > gives
>
Quote:

> > Exception retrieving string: "Cannot find an overload for "XmlNode"
> > and the argument count: "3"."
>
Quote:

> > .. anybody dare to suggest the cause of this bug. Maybe a side effect
> > of the powershell adapter. and an assumption tee-object makes?
>
Quote:

> > -Karl- Hide quoted text -
>
> - Show quoted text -
Hey Shay,

just an FYI: using [ref] in this way doesn't work - that particular
parameter takes a string. I think the reason it appears to work is
because tee-object is silently ignoring the invalid variable name.
replacing [ref] with any other text in square brackets has the same
effect.

- Oisin / x0n
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Is it possible to use Object.Object notation in vbscript ? VB Script
Inherit from usercontrol - Object not set to instance of an object .NET General
datalist -- Object reference not set to an instance of an object. .NET General
Testing object arrays using Compare-Object and -contains PowerShell
Adding canonical aliases for Compare-Object, Measure-Object, New-Object PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46