Program crash with System.ObjectDisposedException
Asked Answered
B

2

9

I'm having a weird problem with my program. I'm developing a windows form application. When I debug it through Visual Studio (F5) it works perfectly correctly, but when I run its executable it crashes and gives me "An unhandled exception of type 'System.ObjectDisposedException' occurred in mscorlib.dll".

I tried to put a top level (on my outermost function) try/catch for catching this exception, but still the program crashes. What am I missing here?

I didn't upload the code because I had to upload the whole code for you to see where the problem is.

Bloem answered 30/7, 2011 at 21:54 Comment(2)
The problem is that when debugging the GC doesn't collect objects that are disposed as often. Somewhere in your code you try to access an object that you no longer have a valid reference to. It has been disposed. It is impossible to say exactly where without some code.Burdett
If he's trying to access it, obviously he must have a reference to it, and thus no GC.Garey
F
3

Wow, an ObjectDisposedException that isn't caught by a top-level catch block?

I'm not sure what I would do in this case - obviously, you want to see the stack trace and find out just what it is that was disposed. There are a few un-catch-able exceptions, but this one isn't one of them. I'd probably attach a handler to the AppDomain.UnhandledException event, and see if that found anything.

Fay answered 30/7, 2011 at 22:33 Comment(0)
I
3

If you can get the stack trace of the exception, it should help you debug the root cause. You may find the Call Stack window helpful for this. Check out the instructions here:

You may also want to disable the "Just My Code" option for debugging in Visual Studio. This may give you better exception debugging information. Follow the instructions (to disable) here:

Imago answered 30/7, 2011 at 22:1 Comment(1)
Updated link: How to: Step Into Just My CodeSaylor
F
3

Wow, an ObjectDisposedException that isn't caught by a top-level catch block?

I'm not sure what I would do in this case - obviously, you want to see the stack trace and find out just what it is that was disposed. There are a few un-catch-able exceptions, but this one isn't one of them. I'd probably attach a handler to the AppDomain.UnhandledException event, and see if that found anything.

Fay answered 30/7, 2011 at 22:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.