Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    Nov 2005
    Location
    Liverpool, Merseyside, United Kingdom
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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.

    Anyone come across this before?

  2. #2
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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...

  3. #3
    New Lounger
    Join Date
    Nov 2005
    Location
    Liverpool, Merseyside, United Kingdom
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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.

    Thanks again
    Kevin

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •