0

I have a console application written in C#. This application runs as automation to test a web service. Flow:

  1. Log in to network share (impersonate user)
  2. copy mp3 file to local disc
  3. convert mp3 to wav
  4. downsample
  5. trim wave
  6. extract some useful data from wav
  7. send http request
  8. delete local files
  9. write out some stuff to tsv

The application will run great for several hours (usually takes about 24 hours to complete the test). but every once and a while I will get this message: "The application has stopped working. I have been running this is VS 2012 in debug mode so, I can see what line throws any error. problem is, that I have not been able to catch the line (or method) that is throwing the error. I originally thought that the Domain controller was causing this issue due to power settings.

How can I capture exactly what error is bubbling its way up the stack?

Matthew Knudsen
  • 213
  • 1
  • 7
  • 19
  • Please edit your question with the `eventvwr` record like [this](http://stackoverflow.com/questions/5701767/windows-application-has-stopped-working-problem-event-name-clr20r3). We'll need the info to see if this is a first or second chance exception and if its in your app or the .Net framework or at a lower level. – Jeremy Thompson Apr 09 '13 at 21:55
  • .NET Global exception handler in console application https://stackoverflow.com/a/3133249/194717 – Tony Aug 20 '21 at 13:32

5 Answers5

2

You can go to the Event Viewer on the operating system the console application is running on and then click on "Application". Event viewer logs and displays all exceptions thrown on any application running on the operating system.

RiceRiceBaby
  • 1,546
  • 4
  • 16
  • 30
  • very nice. totally forgot about that. so this is what the event viewer is spitting out: Faulting application name: FPTest.vshost.exe, version: 11.0.50727.1, time stamp: 0x5011d445 Faulting module name: AdjMmsEng64.dll, version: 10.0.0.7, time stamp: 0x5149b748 Exception code: 0xc0000005 Fault offset: 0x0000000000011adb Faulting process id: 0x2b88 Faulting application start time: 0x01ce34f348432822 Faulting application path: C:\Users\username\Documents\Visual Studio 2012\Projects\FPTest\FPTest\bin\Debug\FPTest.vshost.exe Faulting module path: C:\windows\SYSTEM32\AdjMmsEng64.dll – Matthew Knudsen Apr 09 '13 at 21:53
  • But I still have no idea what that means. – Matthew Knudsen Apr 09 '13 at 21:57
  • 1
    Because `Event Viewer doesn't provide exception details. – Xaqron Apr 09 '13 at 22:07
  • You need adplus with windbg for that - since this is a 2nd chance exception. All these logging answers aint going to yield results. – Jeremy Thompson Apr 09 '13 at 22:08
2

Does all that run in a loop of some kind? Or on a timer?

Perhaps put a try-catch around the body of the loop or the method that runs all your code, add a logging framework of your choice (log4net or nlog seem good) and then in the catch log the exception. Most logging frameworks allow you to include the exception and will include stacktrace, etc.

Putting debug logging throughout the process can also help to narrow down where it's happening.

mutex
  • 7,536
  • 8
  • 45
  • 66
  • Turns out this was an error coming back from the NAudio library that I'm using. putting a try/catch block in the for loop caught this. just frustrating since it took 4 hours to hit the condition – Matthew Knudsen Apr 10 '13 at 01:12
0

I recommend you using a logging framework.

I use log4net in almost all applications. Its very simple to use and configure.

private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

try
{
    // do whatever
}
catch(Exception ex)
{
     // Log an error with an exception
     log.Error("Exception thrown", ex);
}

By using these kind of libraries you can get your log data output to file, database or even written to the windows event-viewer for instance.

Luis Quijada
  • 2,345
  • 1
  • 26
  • 31
0
try
{
   // your code
}
catch (Exception e)
{
   System.IO.File.WriteAllText(@"Z:\err.txt", e.ToString());
}

Note that access to windows drives are denied for non administrators so replace Z: with your choice.

Xaqron
  • 29,931
  • 42
  • 140
  • 205
0

It looks like the exception code you are getting happens when you try to use something that is already been garbage collected. Are you using anything after it is disposed?

Knowledge Base Article for 0xc0000005

Nick Freeman
  • 1,411
  • 1
  • 12
  • 25