Why doesn't my AppDomain.CurrentDomain.UnhandledException event always fire?
I have a Windows Service program running in Release mode that runs 24/7 which makes some in-process COM calls to a C++ library and occasionally 开发者_如何学Cit crashes but the log4net log call in the AppDomain.CurrentDomain.UnhandledException event doesn’t fire.
Instead the process just terminates and a EventLog log message is written … but what’s strange again is that my code doesn’t have any EventLog.WriteEntry calls.
Can some help me figure out why the AppDomain.CurrentDomain.UnhandledException is not firing in all cases?
Thanks in advance
Event log message:
EventType clr20r3, P1 ProgramName.exe, P2 0.0.0.0, P3 4d5bd49f, P4 mscorlib, P5 2.0.0.0, P6 4a7cd8f7, P7 41b3, P8 a3, P9 system.argumentoutofrange, P10 NIL.
The entry in the event log is written by Windows, and is telling you that something is throwing an ArgumentOutOfRangeException. Without seeing the code contained in your event handler for AppDomain.CurrentDomain.UnhandledException
, it's difficult to say why, but it's very likely one of the following is occuring:
- Your exception handler is throwing the
ArgumentOutOfRangeException
- You have multiple AppDomain's in your process and it's one of the other ones throwing the argument out of range exception.
The former is more likely. Review the code in your exception handler very carefully and look for anywhere that a bad argument could be passed. You could try wrapping the entire exception handler in a try
`catch` that logs any exception that occurs within your exception handler to the event log and see if that get you any further information, such as a stack trace.
Also, make sure that you're deploying the debug symbols (.pdb
files) with your application so that any stack traces that get logged give you line numbers to refer back to.
精彩评论