crashes not trapped with MS VS Debugger - how to catch?
I'm getting random crashes from my c# app (Windows 7/VS2008), and it doesn't give me a usual stack trace, but rather suggests to close/debug/find info windows 7 kind of dialog box. I'm running the app either from under VS2008 or stand alone - same thing. Clicking "Debug" suggests to debug with a new instance of the VS, which fails as "another debugger's already attached to the app". But the attached debugger does not give me any chance to see where it fails, just gives some clues in the output window (below). How to deal with this?
It looks like I have to enable (?) first chance exceptions in the VS debugger, but it was unclear开发者_JAVA技巧 how.. I appreciate any help with this!
Addition - I found how to enable debugging the exceptions in VS2008 (Debug->Exceptions->checked all the 5 categories of exceptions). And it still gives me exactly the same result - crash without ability to see what's going on in debugger.
'PS.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Deployment\2.0.0.0__b03f5f7f11d50a3a\System.Deployment.dll' A first chance exception of type 'System.Deployment.Application.InvalidDeploymentException' occurred in System.Deployment.dll A first chance exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll The thread 0x1964 has exited with code 0 (0x0). The thread 0x1b24 has exited with code 0 (0x0). A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll A first chance exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll The thread 0x19b8 has exited with code 0 (0x0). The thread 0x18f4 has exited with code 0 (0x0). The thread 0x420 has exited with code 0 (0x0). A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll The program '[6084] PS.exe: Managed' has exited with code -1073740940 (0xc0000374).
It is sorta like witnessing one of those massive pile-ups at a formula 1 race. The last bit of shrapnel that came to a rest reported:
// MessageText:
//
// A heap has been corrupted.
//
#define STATUS_HEAP_CORRUPTION ((NTSTATUS)0xC0000374L)
Yes, that's a very serious tire blow-out. Lots of things go wrong when a heap gets corrupted. You've probably got some unmanaged code that's misbehaving in a way that's so typical of unmanaged code, destroying the integrity of the heap with a bad pointer write. Very hard to diagnose, isolate that code.
In VS, go to Debug / Exceptions, and activate the check box under 'Thrown' for 'Common language runtime exceptions'. This will catch the 'first-chance exception'.
A deployment exception seems to be related to Click Once. Are you using it ?
create an output log file or use message boxes to track it down, if the development tool fails you.
Press Ctrl
+ Alt
+ E
in Visual Studio or Choose Debug > Exceptions from the menu and then click CLR Exceptions to catch all first chance exceptions. That should then hopefully break at the point of contention.
Otherwise, try write Debug.Write
and Trace.Write
statements at critical points in your code to see what point you reach before the failure occurs. Both Debug and Write can be found in System.Diagnostics
namespace.
IMO the best to debug heap corruptions is using Windbg. Here is a blog post from Tess on debugging managed heap corruption.
HTH
精彩评论