c# - Stream - Cannot access a closed Stream -
small issue i'm having stream, i'm getting exception in title.
i have inside using statement, inside loop, , posts i've seen remove using statement , "renew" it: cannot access closed stream of memorystream, how reopen?
the exception happens on second iteration of loop. have tried removing using statement no effect.
here's general idea:
for (blah blah blah) { using (stream strm = externalstreamprovider.getstream(some params) { if (stream.position != 0) //exception here on 2nd iteration ........... } } however, using stream, abstract, cannot recreate mystream = new stream().
i using external stream provider, cannot change how stream fetched.
any ideas on how fix issue?
i apologize vagueness, please let me know if unclear.
it seems externalstreamprovider returning same stream instance every time... , since closed in first iteration, fails in second.
if expect working same stream in every iteration, should stream outside loop:
using (stream strm = externalstreamprovider.getstream(some params) { (blah blah blah) { if (stream.position != 0) ........... } } edit: saw comment:
when exception raised on
stream.positionbrand new instance of stream on 2nd iteration
in case, explanation externalstreamprovider returning stream closed; problem not in code posted...
Comments
Post a Comment