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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Dipal ChoksiRank #199 · 12K reputationPosted May 12, 2008, 8:41 PM EDT
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..
George GeorgeRank #1,736 · 870 reputationPosted May 12, 2008, 8:51 PM EDT
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 ChoksiRank #199 · 12K reputationPosted May 14, 2008, 9:21 PM EDT
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 GeorgeRank #1,736 · 870 reputationPosted May 14, 2008, 9:32 PM EDT
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 ChoksiRank #199 · 12K reputationPosted May 18, 2008, 10:52 PM EDT
George GeorgeRank #1,736 · 870 reputationPosted May 21, 2008, 6:01 AM EDT
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