Steve,
you're serializing to a binary format so you can't rad it back as a string.
Try the BinaryReader() or use the XmlSerializer ( which has certain
constraints ) for an XML based serialization format.
HTH,
Christoph Schittko
Software Architect
Mshow - a division of InterCall
----- Original Message -----
From: "Steve Holak" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, May 20, 2002 4:12 PM
Subject: [DOTNET] Object serialization to string representation
> I'm trying a test function to serialize an object to a string (to
> eventually upload the string to a database for storage). The object
> serializes just fine to disk creating a Stream as a File.IO.
>
> What I'm encountering is trying to serialize to a MemoryStream and reading
> it back with a StreamReader; in the code below the string "test" is always
> empty ("")
>
> The "this" reference is the object itself which contains the serialization
> implemetation.
>
> What am I missing, and is there a simpler way to return the string
> representation of a serialized object without writing to disk?
>
> Stream stream = new MemoryStream();
> BinaryFormatter formatter = new BinaryFormatter();
>
> formatter.Serialize(stream,this);//this is the object
saving
> itself to the db.
> StreamReader sr =new StreamReader(stream);
>
> sr.BaseStream.Seek(0, SeekOrigin.Begin);
>
> //test always shows ""
> string test=sr.ReadToEnd();
>
> stream.Close();
>
> TIA
>
> Steve Holak
> Senior Software Architect
>
> Brokerage Concepts IS Dept.
> 610-491-4879
>
> email: [EMAIL PROTECTED]
>
> You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
> subscribe to other DevelopMentor lists at http://discuss.develop.com.
You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.