How can you know if a stream is closed? [closed]
I have a method with a Stream for input :
public void Export(Stream finalOutPutStream)
For test purposes, i call it with a memory stream, like this :
// When
_exporter.Export(new System.IO.MemoryStream());
But when, in the method, i want to write on this memory stream, i get a ObjectDisposedException.
This stream is not enclosed in a using statement, i do not call explicitely .Dispose().
What happened ?
Thanks :)
-- EDIT : my bad, the problem is from the third party writer (DotNetZip). The exception happens when i call zip.Save(new MemoryStream()). I will ask my questions on their forum. Sorry, and thanks for the help.
You can check stream availability using: CanRead
, CanSeek
, CanWrite
properties.
if you put the stream creation inside using it will do the closing and resource release for you EX:
using(Stream s = new MemoryStream())
{
// do your operations
}
精彩评论