Search

Deserialized objects are missing the GetType method in PowerShell 2 and 3 by Kirk Munro

Active

12
0
Sign in
to vote
Type: Bug
ID: 779256
Opened: 2/14/2013 2:58:02 PM
Access Restriction: Public
1
Workaround(s)
2
User(s) can reproduce this bug
If you receive objects from a call to Invoke-Command, they come back deserialized. These deserialized objects are missing the GetType method. GetType should be there on all objects, deserialized objects included (in which case I would expect it to tell me the objects are PSObjects).
Details (expand)
How often does this happen?
Always Happens

Have you seen this problem before in this product?

Yes, this happens in all previous versions
Reproduction Steps
$x = Invoke-Command -ComputerName localhost -ScriptBlock {Get-Service wuauserv}
$x.GetType() # Fails with an error
Expected Results
GetType should return PSObject in this case (since that's what it is, which can be seen by invoking [Type]::GetTypeArray($x)[0].FullName).
File Attachments
0 attachments
Sign in to post a comment.
Posted by Matthew Reynolds [MSFT] on 2/18/2013 at 11:34 AM
+1 on expecting these to implement gettype(). Just last week I was writing a script which needed to understand deserialized objects and I was surprised when gettype() didn't work.

In contrast to Kirk, though, my expectation was that the type would be Deserialized.Foo.Bar as shows up in some places, as opposed to just psobject.

Either would be better than nothing.
Posted by Keith Hill MVP on 2/15/2013 at 9:45 AM
I expect *all* .NET objects to have a GetType() method! That's fundamental to .NET.
Sign in to post a workaround.
Posted by Kirk Munro on 2/14/2013 at 2:58 PM
Use Get-Member to see if the object has a GetType method. If not, it is a PSObject that is representing an object that was deserialized from another session.