Reusing an open FileStream with multiple BinaryWriter objects

Hi all,

a quick question: Part of my application (Windows Forms / C# / .NET 2.0) deals with different objects which all have Serialize / Deserialize methods (custom ones, not implementations of ISerializable). At some point, I create a FileStream for writing, and then need to call those objects in turn, passing the FileStream object to the Serialze method. Each object should then append some binary data to that stream (and the reverse process for deserialization, of course).
The problem: When first creating, say, a BinaryWriter, passing the FileStream, everything works fine, and the data is written. However, when the writer is closed or disposed of, the stream will be closed as well, so the next object fails to attach its BinaryWriter to it. Is there any way to prevent that from happening Or to reopen a stream once it has been closed Or any other suggestion how to deal with the situation

Thanks in advance,
Guido



Answer this question

Reusing an open FileStream with multiple BinaryWriter objects

  • Reusing an open FileStream with multiple BinaryWriter objects