Showing posts with label Exception. Show all posts
Showing posts with label Exception. Show all posts

Sunday, April 21, 2013

clr20r3 P9 system.componentmodel.win32 : Handling unhandled exceptions

The problem : An Application that doesn't start


Happened to come across an older (read dot net 2.0) application which , due to some reason started to misbehave. whenever it is started it said "App has encountered a problem and needs to close. We are sorry for the inconvenience". There are no other details and the only point of hope was the windows log which said.

EventType clr20r3, P1 app_name.exe, P2 1.1.2.0, P3 4f1ea58b, P4 system, P5 2.0.0.0, P6 4889de7a, P7 3839, P8 131, P9 system.componentmodel.win32, P10 NIL.

I was also told by the dev guys that the application is having its own error log which does not show any entry of this error and also the infamous excuse of "It worked yesterday."   and "It is working fine on my machine."


The source


Going through the source code , found that all the methods had try catch blocks with exception logging configured to log everything including stack trace. Even all the line of codes inside the static Main() were enclosed in a try catch.


The Solution


Since there was no handler for unhandledexception written, the same was added just inside the Main()

           AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(delegate(object sender, UnhandledExceptionEventArgs e)
                {
                  if (e.IsTerminating)
                  {
                      object o = e.ExceptionObject;
                      MessageBox.Show(o.ToString()); // use EventLog instead
                  }
                }
            );



This snippet makes sure that no exceptions are unhandled from your side. [On a lighter note, the root cause here in this case was revealed to be an error log which grew out of size]
I suggest the usage of this handler for trapping any exception that stays unhandled.


Understanding the error log [Watson buckets]



For Breaking up the windows error log entry
EventType clr20r3, P1 app_name.exe, P2 1.1.2.0, P3 4f1ea58b, P4 system, P5 2.0.0.0, P6 4889de7a, P7 3839, P8 131, P9 system.componentmodel.win32, P10 NIL.
The entries P1 ,P2 ,P3 etc are the details collected by the system regarding the exception that went unhandled. They are known as Watson buckets. They include the following information


  1. Executable
  2. Assembly version number
  3. File Stamp
  4. Full assembly name
  5. Faulting assembly version
  6. Faulting assembly timestamp
  7. Faulting assembly method def
  8. IL Offset within the faulting method
  9. Exception type




Hopes this helps someone, someday, some time...
Happy Programming...