Hello everyone,
Any general rules/practices to avoid "ObjectDisposedException"-- System.ObjectDisposedException: Cannot access a disposed object?
thanks in advance,
George
Hello everyone,
Any general rules/practices to avoid "ObjectDisposedException"-- System.ObjectDisposedException: Cannot access a disposed object?
thanks in advance,
George
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
George GeorgePosted May 21, 2008, 10:01 AM
Thanks Dipal,
Is it possible to determine which object is Disposed and when it is Disposed? I only catch the exception, but no idea which object is disposed?
Could I get information of which object is disposed from the exception information or some other ways to detect which object is disposed?
regards,
George
Dipal ChoksiPosted May 19, 2008, 2:52 AM
George GeorgePosted May 15, 2008, 1:32 AM
I get the exception from server side when call End method almost every time when I disconnect in the middle from client. Any ideas?
regards,
George
Dipal ChoksiPosted May 15, 2008, 1:21 AM
I am curious - are you getting the exception every time the code executes or does it happen when the item you are trying to access has timed out/closed the connection etc?
George GeorgePosted May 13, 2008, 12:51 AM
Thanks Dipal,
1.
I have checked that the exception is from EndGetContext method of HttpListener class, when will it throw ObjectDisposedException?
2.
I find the EndGetContext method can throw ObjectDisposedException. So, my solution is to catch it, is it the correct solution?
http://msdn.microsoft.com/en-us/library/system.net.httplistener.endgetcontext(VS.85).aspx
regards,
George
Dipal ChoksiPosted May 13, 2008, 12:41 AM
Try to avoid situations where disposed objects are accessed..
If possible, check for the existence/validity of an object before accessing it...
In some cases, adequate testing may help..