I've got an Umbraco site using a fair ammount of usercontrols in which, somewhere - somehow, a stackoverflow exception gets thrown every now and then.
Since the SOE doesn't occur when testing is has something to do with a user posting or getting some information (fair enough: something I've missed).
How can I trace back where my stackoverflow exception took place inside my code? Are there tools available to check my sources to see if I've missed some recursive method? Or how can I debug the running process?
I have found that debugging the application (sometimes having to attach VS to the correct w3wp.exe process) and setting VS to break on exception is the most helpful. You could still see the stack trace which is full of the same series of method calls.
If the application crashes, enable this registry setting to create a crashdump for all crashing apps:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps]
"DumpFolder"="C:\\TEMP"
"DumpCount"=dword:00000010
"DumpType"=dword:00000002
It will create a crash dump in your C:\Temp folder. Either open this dump file in a newer version of Visual Studio which will show you the exact code it crashed (just like if you where debugging and you got an unhandled exception).
Or an extremely useful MS tool for all your dump analysis needs: Debug Diagnostics Tools (https://www.microsoft.com/en-us/download/details.aspx?id=49924). Video walkthrough here: https://channel9.msdn.com/Shows/Defrag-Tools/Defrag-Tools-123-DebugDiag-Part-3
This will analyse your crashed application and show you all the threads and their managed and unmanaged stacktraces.
It will likely point out exactly the issue of your crash and where it occurred so you can check that stacktrace.
If however the program did not crash, you can open task manager and rightclick the process and create a dump file manually. Sending this dump file through Debug Diagnostics on a crash analysis it will show you the last X exceptions that did occur in your application with stacktraces. I use this method to find the actual error of user applications when the user gets a nice simplified error message. As an alternative to creating a dump from taskmanager you can also use procdump.exe or Debug Diagnostics itself to create rules on when to create dump files.
I really believe more people should be aware of how incredible easy a DUMP file together with Debug Diagnostics is to find any error that occurred in a production environment, where we don't have our handy development tools available.
Related
I’ve got a c++ dll written in visual studio 2012. I’d like to load it in a C# program(VS2012 too) with using of LoadLibrary function.
I set the SetLastError = true to get the probabilistic returned error code by LoadLibrary. When I run my C# program I always receive 998 error code but I can’t understand what’s wrong with it!
Should you help me to resolve this problem,please?
Any help would be appreciated.
(It should be mentioned that I saw some posts about error code 998 but none of them couldn't give me a solution.)
In response to this comment "please tell me how can I do this instruction":
To troubleshoot the LoadLibrary() failure, run the application under a
debugger and enable first chance exception handling for the C0000005
Access Violation exception. If an access violation occurs when the
LoadLibrary() function is called, the application will break into the
debugger. The debugger's call stack can then be used to trace where
the exception occurred. The stack trace should help you narrow down
the actual problem related to the exception being encountered.
Open your project in Visual Studio
In the menu, click Debug > Exceptions
In the Exceptions window, click Find... and enter C0000005 click Ok
Check the box next to the highlighted exception under the column Thrown.
Now, when you debug your program and the exception is thrown, it will break and you should be able to at least inspect the exception details of the thrown exception.
It's likely you'll be thrown into disassembly window so you may not see any readable code. If the exception detail isn't enough, you could try decompiling with Dot Peek.
Here's a tutorial on enabling Dot Peek as a symbol server. Doing this will hopefully decompile the library on-the-fly so you can start inspecting the line of code that has caused the exception.
For the tl;dr crowd:
What is causing type names to be written to the output window if it isn't Console.WriteLine or Debug.Print statements in the code? Is it the Visual Studio debugger? and
How can I turn it off?
Background and details:
I am trying to debug a program that imports CSV files into a database. Recently, I changed how I include 3rd party library dependencies. Previously, I was referencing the downloaded binary files. Now, if a 3rd party library has source code available, such as NHibernate, the project is included in my solution to be compiled along with the projects I have written myself.
Since the change, I am seeing a lot of single lines containing only a type name in the Output/Debug window that I didn't used to see before. My program is a data importer, and the main loop is causing these lines to appear 1000s of times, slowing down debugging and polluting the output window. Specifically, there are a lot of lines that say this:
NHibernate.Driver.NHybridDataReader
I have traced the code, and it seems that this is displayed whenever NHibernate is reading results back from the database. However, the line isn't output in code by the NHibernate library, so it must be coming from somewhere else. My guess is that the Visual Studio Debugger is writing it to the output window, similar to what happens during assembly binding.
I have tried compiling the NHibernate project in Release mode and everything else in Debug mode, but that didn't fix it. I also tried unchecking "Enable the Visual Studio hosting process" for just the NHibernate project, but that didn't work either.
In summary, my questions are:
What is writing type names to the output window if it isn't Console.WriteLine or Debug.Print statements in the code? and
How can I turn it off?
What my question is not
My question is NOT about a better way to write the data importer program so that the needed data is preloaded from the database. I know the code I have written is slow; in this particular case, in production, that is okay. What I want is to stop polluting the debug window with tons of unneeded type information. The work loop of my program causes the types to be written 1000s of times for long CSV files, which makes the output hard to use, and slows the debugger down as it tries to sync the output window. THIS is what I am trying to prevent. But I'm not sure how to do that, because I'm not even sure where the messages are coming from.
It's difficult to make suggestions without being able to see the code, but what I would do to debug it is install the trial version of RedGate's Reflector and use it to add breakpoints to the Debug.* and Console.* functions. If one of the breakpoints is hit, you can trace back up the call stack to find what is actually adding the lines to the output. If none of those methods are causing the lines to be added, maybe add breakpoints to DefaultTraceListener and TextWriter.
I haven't come across anything else which can add messages to the Visual Studio output window at run time.
I think this is irrelevant, though it solved my seemingly unrelated problem a while back (I had automated tests randomly failing and printing to console). I had to uncheck Visual Studio's "Enable property evaluation and other implicit function calls" under the Debugging menu in Options. Sorry if this is off topic/unhelpful!
EDIT: Also, have you tried changing the 'Output Window' settings in the Debugging section? You could maybe turn all debug output off and print your own debugging to a file.
Let's say I have a .NET application that crashes when I close it and I want to use DebugDiag to see what is going on. So we should create a dump file. My question is When do we create this dump file? Should I create it when I start the application? well if I do that it says a dump file has been created at this temp location...ok..then I continue working the application and make it to crash, but my confusion is that well it created the dump file very early, but crash happened at the end, so how even that dump file can be helpful? does it like get updated automatically once we are working with that application?
For a crash (which is usually an unhandled exception) you should create the dump file when the exception becomes a second chance exception. I am not very familiar with DebugDiag, but tools such as adplus (Debugging Tools for Windows) and ProcDump will both let you create dumps for this.
In some cases you may want to create dumps for first chance exceptions as well (i.e. before any code gets to handle the exception). E.g. if the exception which causes the crash wraps some other exception you may not have enough information at that point. In those cases creating dump files on first chance exceptions will give you detailed information on the state of the original exception.
You can configure windows to create dump files when the process crashes. This feature is not enabled by default: Collecting User-Mode Dumps. The process is different for Windows XP: Capturing Application Crash Dumps. Once you have the dump file you can open it and investigae with WinDbg. I highly recommend blog by Tess Fernandez and this book.
Hi I made some changes in a windows service coding side(some class files related to that),,means i did coding to fetch version value from registry in that class files,,,,After
Your OnStart method is most probably hanging. Did you recently add any of that threading/timer code.
Is your tracer logging any information?
Can you write some debug code to log where you are getting to and what exceptions are being thrown?
So it looks like OnStart is throwing an exception (in SpoER.Init()?, and it has permissions problem as well), this is causing the service to try and stop straight away.
I would suggest following the exception information you have given to try and locate the problem. It would be even better to move the bulk of this code into a separate class so you can write a console app which shares the same code as the service. By using the console app you can easily debug it.
Now i got the mistake,,What actually i was doing is i am copying DLL created in the debug mode and copying into the Installer path..Actually what i need is i have to copy DLL obtained from the release mode and copy into the installer side
I work on an open source product called EVEMon written in C# targeting the .NET 2.0 platform, I have one user who is suffering from a strange .NET crash that we have been unable to resolve.
Event Type: Error
Event Source: .NET Runtime 2.0 Error Reporting
Event Category: None
Event ID: 5000
Date: 4/29/2009
Time: 10:58:10 PM
User: N/A
Computer: removed this
Description:
EventType clr20r3, P1 evemon.exe, P2 1.2.7.1301, P3 49ea37c8, P4
system.windows.forms, P5 2.0.0.0, P6 4889dee7, P7 6cd3, P8 18, P9
system.argumentexception, P10 NIL.
Data:
//hex representation of the above Description
The application itself crashes with out displaying an error (despite having a error handling UI), the above messages was copied out of the Windows Event log. The end user has re-installed .NET and updated to the latest versions. The .PDB files are distributed with every release version of the program to aid in debugging and testing, the user with the problem in question has the full complement of PDB files for the correct version of EVEMon.
Is there a specific, tried and tested technique to analyse and diagnose this type of crash? and if so what tools and technologies are available to aid in debugging?
Special Thanks
I would like to give special thanks to Steffen Opel and highlight that his answer whilst not directly answering the question I was asking, addressed the bigger issue with my code base that the global error handling was missing an important component.
This is how I would tackle the problem for a end user with a crash.
Download and install Debugging Tools for Windows at http://www.microsoft.com/whdc/devtools/debugging/default.mspx
Once the tools are installed (they end up going to C:\Program Files\ by default) start a command line window.
Change to the directory which contains adplus (e.g "C:\Program Files\Debugging Tools for Windows (x86)").
Run the follwing command. This will start the application and attach adplus.
adplus -crash -o C:\debug\ -FullOnFirst -sc C:\path\to\your\app.exe
After the crash dump is created
Once the application crashes start WinDbg and load the .dmp file that is created in C:\debug. (File --> Open Crash Dump)
Execute these commands to see the stack trace and hopefully find the problem.
To load SOS for debugging
Pre .NET 4.0
.loadby sos mscorwks
.NET 4.0
.loadby sos clr
To see the stack trace
!clrstack
To see a more useful stack trace
!clrstack –p
To poke inside an object..perhaps see what caused the exception
!do <address>
e.g This is the result from a application that faulted randomly with an IO exception. WinDbg pointed out the path that was being referenced which was incorrect.
0:009> !do 017f2b7c
Name: System.String
MethodTable: 790fd8c4
EEClass: 790fd824
Size: 124(0x7c) bytes
(C:\WINDOWS\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll)
String: \\server\path\not_here.txt
Fields:
MT Field Offset Type VT Attr Value Name
79102290 4000096 4 System.Int32 1 instance 54 m_arrayLength
79102290 4000097 8 System.Int32 1 instance 53 m_stringLength
790ff328 4000098 c System.Char 1 instance 5c m_firstChar
790fd8c4 4000099 10 System.String 0 shared static Empty
>> Domain:Value 00161df8:790d884c <<
7912dd40 400009a 14 System.Char[] 0 shared static WhitespaceChars
>> Domain:Value 00161df8:014113e8 <<
Peeking into your source code (trunk) indicates that your unhandled exception handling seems to be incomplete in regard to Windows Forms applications:
You need to handle both non-UI thread exceptions and UI thread exceptions:
For the former you need to implement a CLR unhandled exception handler via AppDomain.CurrentDomain.UnhandledException, which is in place already.
For the latter you need to implement a Windows Forms unhandled exception handler via Application.ThreadException, which seems to be missing; this could indeed yield exactly those problems you are witnessing. For an implementation example see MSDN documentation of Application.ThreadException Event.
Please note that right now you explicitly suppress catching unhandled Windows Forms exceptions via Application.SetUnhandledExceptionMode(UnhandledExceptionMode.ThrowException), you'll need to change this to UnhandledExceptionMode.CatchException to enable routing to your handler for Application.ThreadException, as correctly suggested by Jehof already.
What OS (Windows XP, Windows Vista, etc.) does the user use?
If Windows Vista try to disable "Problem Reports and Solutions feature" (Control Panel-->Problem Reports and Solutions-->Change Settings-->Advanced Settings-->Turn off for my programs, problem reporting)
Or try to set
Application.SetUnhandledExceptionMode( UnhandledExceptionMode.CatchException );
This will always route exceptions to the ThreadException handler.
In a nutshell: there is an unhandled exception in the application.
If you have access to the machine (through remote access, etc.), try installing Visual Studio Express and starting the application. You should see a dialog offering the chance to debug the application with a new instance of Visual Studio.
It may also be that there is something preventing Windows Forms from properly initializing. I've seen forum posts that suggest that font issues can cause this -- ensure that the users have the fonts installed that your application needs plus the usual defaults such as MS SansSerif, Arial, Tahoma, Times and suchlike.
And failing that... try sacrificing a chicken over the PC. Works a charm every time!
We've had issues with Exceptions in Thread-Code. If you spawn a new Thread and forget to handle an exception in the thread method, the application just "stops" - no error message, no nothing, but only an entry in the Event Log. Not even then UnhandledExceptionHandler is triggered.
Maybe something like this is the cause?
...if you are able to contact that suffering user, here is an
Idea: log pre-execution stages
Instead of making a shortcut to your program.exe, make a shortcut to program.bat, which will
echo "Pre-start" > stage.txt
start program.exe
The first line of Program.cs will therefore be
File.WriteAllLines("stage.txt", "Program execution started.");
In the handler of AppDomain.UnhandledException first line will be
File.WriteAllLines("stage.txt", "Unhandled exception has been caught.");
Also, make sure that the handler does not allocate memory or resources — pre-allocate them on programs start. Handler only trigger the writing to the log.
Comments
It is very likely that the stage.txt (sent by the user) will contain "Pre-start". This happens when an exception is thrown in 3rd party .dll — even before your program has started.
In that case you will need a simple checker program, which will not reference the assemblies that you program.exe does, but will Assembly.Load(...) them.
P.S.
stage.txt should be placed somewhere under %APPDATA%, not in Program Files.
I found an interesting case on Server 2003 and another nice discussion.
You should get a more detailed stack trace by sending the .pdb file for that particular release to the user (to be put next to the .exe) and having them reproduce the crash.
You should handle AppDomain.UnhandledException in code.
There was a similar question asked. See related ones too.