Cannot access a closed Stream. Error throwing
How to resolve?
Cannot access a closed Stream. Error throwing
How to resolve?
This is because something that opens things in memory, e.g streamreader, StreamReader
closes the underlying stream automatically when being disposed of. The using statement does this automatically.
However, the StreamWriter
is still trying to work on the stream (also, the using statement for the writer is now trying to dispose of the StreamWriter
, which is then trying to close the stream).
The best way to fix this is: don't use using
and don't dispose of the StreamReader
and StreamWriter
. See this question.