3

Situation:

I have an application that uses http connections extensively (stream ripping app) and it is supposed to work 24/7. And it does.

However, occasionally, it crashes with runtime error that is uncaught anywhere, and dumps following to the event log:

Event Type: Error
Event Source:   .NET Runtime 2.0 Error Reporting
Event Category: None
Event ID:   5000
Date:       13.10.2010
Time:       11:02:30
User:       N/A
Computer:   STREAM01
Description:
EventType clr20r3, P1 streamsink.exe, P2 1.0.0.42484, P3 4c880fd9, P4 mscorlib, P5 2.0.0.0, P6 4add54dc, P7 344a, P8 21c, P9 system.io.ioexception, P10 NIL.

My question is: how to know what line of code caused the crash. I am deploying .PDBs with the binaries, but... What to do?

Target is WIndows XP, Framework is 2.0

EDIT:

I have this already implemented:

    static public void InitializeExceptionHandler(string AppName) {
        Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
        Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
        AppDomain currentDomain = AppDomain.CurrentDomain;
        currentDomain.UnhandledException+=new UnhandledExceptionEventHandler(currentDomain_UnhandledException);
        _appName=AppName;
    }

No, it doesn't work!

6
  • 1
    This is sort of a leak at SO. Tens of thousands of questions that are all different but have the same answer. Implement AppDomain.UnhandledException and log/display/email/print e.ExceptionObject.ToString(). Commented Oct 18, 2010 at 22:11
  • @Hans: unfortunately, that doesn't help. There are exceptions that are handled, but this one here goes unnoticed. Commented Oct 18, 2010 at 22:56
  • 1
    It is just an IOException, one of the most common ones. Bread and butter stuff, there's something wrong with your code. We can't see the exception handler in your snippet, it possibly does something unwise like not calling Environment.Exit() after sending you an email. Commented Oct 18, 2010 at 23:01
  • @Hans: Hm..... Application works for 5 days and crashes on next day, having handled 100 shoutcast streams and recording them to disk. Yes there is something wrong, but I can't get the exception in my hands and want to know why. And yes, I'm not terminating the application because when an exception IS caught, it terminates itself after displaying the message to the user. Commented Oct 18, 2010 at 23:09
  • Are you saying that your user didn't give you an accurate rendition of what was displayed in the message box? Yes, that happens. Hide the OK button. Commented Oct 18, 2010 at 23:21

4 Answers 4

4

Register current domain's unhandled exception in the entry point (Main() or ...):

AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

Implement logging in the handler:

static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            // log
        }

Application will still crash but you will get the full logging of what happened and stack trace.

UPDATE

According to the update you have, I suggest you download debugging tools for windows http://www.microsoft.com/whdc/DevTools/Debugging/default.mspx and then enable post-mortem debugging and make sure a crash dump is created (see Enabling Postmortem Debugging section in Windbg help file) and use Windbg to debug your dump to find out where it has crashed.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you but I have that in place, also handling ThreadExcetion. No bread there. :( see my edit...
3

Maybe this article will be helpful A Simple Class to Catch Unhandled Exceptions in WinForms

UPDATE:

It very strange.. So grab ProcDump, write batch file and ask your customer to run it when he see error message. Get dump and try to investigate it via WinDbg or VS 2010. Here some more information.

Also check: Creating and analyzing minidumps in .NET production applications. If you are new to WinDbg, check Tess Ferrandez's blog

Another way go with Remote Debugging Setup

4 Comments

Thanks, but this is somehow deeper than that... see edit and other comment.
What is your application, A windows service or an ASP.NET app?
!Aliostad: it's winforms... most of the time exceptions ARE caught in the handler, but not always.
@Daniel: But if you catch them why not analyze? If you certainly sure you get exceptions pass thru any handlers, try my (or @Giorgi its similar) way. It may seems not so easy to follow but it gives you exact reason.
2

You can use Adplus to automatically save minidump whenever an exception occurs. See this question for details: Fastest way to break in WinDbg for specific exception? .net 4.0 app.

2 Comments

Khm, I'm on .net 2.0... worth looking?
@Daniel - Definitely. Adplus is available for .Net 2.0 too.
1

If unable to implement an exception handling solution, you can implement some trace logging to narrow down the location in the code and which stream are causing the exception.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.