Reputation: 6391
I have machine that I need to analyze for information. I use powershell to gather the information into an object and then I write that object out to a file using Export-Clixml myObject.xml
.
I then try to test import this object using $placeholder = Import-Clixml myObject.xml
and this works fine as I can see all the methods and access data in the methods.
However, whenever I try to use this object in my program where this type of object is required, I get a Type Mismatch
error.
Is this not possible with serialized object?
Upvotes: 1
Views: 4109
Reputation: 201902
If you look at the full typename of the objects you deserialized you will see that they begin with "Deserialzed". For instance if I take a bunch of System.Diagnostics.Process
objects and export them using Export-Clixml, when I use Import-Clixml to import them, the types are now Deserialized.System.Diagnostics.Process
objects. What PowerShell is doing is saving the data out and then giving you access to that again. You're not getting back live objects. Typically the only method available is ToString()
. This is similar to what happens with serialization over remoting. If you want full fidelity .NET type serialization. I would use one of the .NET serializers such as the BinarySerializer or the XmlSerializer or the newer DataContractSerializer.
Upvotes: 1