Thursday, 12 September 2013

How can I use a BinaryFormatter to serialize an object for reuse?

How can I use a BinaryFormatter to serialize an object for reuse?

I have an object that I need to store as a file and use it later on a
different machine. I'm very new to powershell and based on what I'm
reading, it seems like I'm trying to do some advanced powershell
techniques.
So far I've created a BinaryFormatter like this:
$formatter = new-object
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
I then created the object required by the Serialize method by doing the
following:
$fileOut = New-Object System.IO.FileStream c:\testOut, 'Append'
I then took this and tried to pass it this way:
$formatter.Serialize($fileOut, $myObject)
I then get an error saying that one of my objects isn't serializable. I
don't even know if what I'm doing is correct. Can someone please guide me?

No comments:

Post a Comment