ObjectDisposedException (C#)

I'm passing a MemoryStream reference through several object layers' methods, eventually reconstituting the XML it contains. However I keep getting an ObjectDisposedException that doesn't make any sense to me ( I'm not closing anything and certainly not manually disposing of it ). I can fix the problem by instantiating a new MemoryStream within each method, using the argument to populate it, but this just doesn't seem right to me.

Re: ObjectDisposedException (C#)

This sounds like a scope problem. It seems that your variable is loosing scope at some point. Can you post any samples of your code, or define the structure a bit more? It's hard to say without knowing a bit more about what exactly is happening...

Re: ObjectDisposedException (C#)

Mark, thanks.

I checked for scope problems (triple checked) but it was OK on that front. However, I have found out what the problem is.
I'm passing the MemoryStream into a series of XmlTextWriters/ XmlTextReaders. When I ( quite reasonably I think ) close the Writer/Reader objects I am also inadvertently closing the MemoryStream. Now this doesn't seem to behave as I would have expected (i.e. I would expect the MemoryStream to be populated and sit in memory so I don't need the Writer/Reader any more).
My work around is to create a local MemoryStream for use by the Writer/Reader and copy the passed in stream to it.