Small issue I'm having with a Stream
, I'm getting the exception in the title.
I have it inside a using
statement, which is inside a loop, and most posts I've seen just say to remove the using
statement and "renew" it: Cannot access a closed Stream of a memoryStream, how to reopen?
The exception happens on the second iteration of the loop. I have tried removing the using
statement with no effect.
Here's the general idea:
for (blah blah blah)
{
using (Stream strm = externalStreamProvider.GetStream(some params)
{
if (stream.Position != 0) //exception is here on 2nd iteration
...........
}
}
However, I am using Stream, which is abstract, so I cannot recreate it like myStream = new Stream()
.
I am using an external Stream
provider, so I cannot change how the Stream
is fetched.
Any ideas on how to fix this issue?
I apologize for any vagueness, please let me know if something is unclear.