views:

162

answers:

5

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

A: 

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 ?

Timores
I was wondering about the deployment exception, too.
Beth
Thanks! No, I don't use or at least I don't know what "Click Once" is. As I've added to the description - even checking all the exceptions didn't break the code to the debugger...
Jim
Anyway - I've been able to isolate the crash messages - cleaning output window and checking all the exception types in the Debug->Exception dialog _right_before_ doing the action (now a known point in the application), which generates the crash, which doesn't go to the debugger.All it says - The program '[6988] PhotoSoftware.exe: Managed' has exited with code -1073740940 (0xc0000374).This is the only line left after crash. So, heap corruption, huh. Some investigation to do now...
Jim
Does it make sense to remove some code to the 3rd party components and test, until you find which call causes the crash ?
Timores
A: 

create an output log file or use message boxes to track it down, if the development tool fails you.

Beth
that seems to be the only chance to see where it fails now... thanks!
Jim
A: 

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.

desigeek
A: 

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.

Hans Passant
HMMMM. Looks like you're right. I've just been able to isolate and fix the "argument out of range" and other exceptions with this method. But now all it says on crash in log is:The program '[6988] PhotoSoftware.exe: Managed' has exited with code -1073740940 (0xc0000374).Which seems to be what you're talking about. HMMM... =(
Jim
Oh, okay, just one car hitting the wall then. You still need to chase the source of the problem. Unit-test the heck out of any unmanaged or COM component you are using.
Hans Passant
...leaves me clueless here, I'm sorry - this is my 3rd large C#.NET project (experienced with C++ and many others, though) - I don't even know how to identify the unmanaged code or COM component. I'm using the Attilan Chrystal Image Toolkit and several components, like FileBrowser, ImageButton and EnhancedWebBrowser.Feels like it would be hard to help me to move forward with this information, or you could point into the right direction to dig?
Jim
I'm sorry too. You haven't provided any information that would help us help you further along. You've got plenty there that can screw you up. Work with the vendors of those components if you need support.
Hans Passant
I understand, of course. Thanks a lot anyway, at least I know that's the heap and the direction to look now! =)
Jim
Okay, good luck with it. Please close your thread by marking it answered.
Hans Passant
A: 

IMO the best to debug heap corruptions is using Windbg. Here is a blog post from Tess on debugging managed heap corruption.

HTH

Naveen