Search code examples
c#.netstreambinarywriter

Why a BinaryWriter closes the outer Stream on disposal, and how to prevent that? (.NET C#)


I have one method that receives a Stream to write on it using a BinaryWriter. But when I dispose this BinaryWriter it also closes the stream. Can I leave it undisposed so I can leave my stream open?


Solution

  • Just do not call Dispose, use Flush instead, its safe.