Issue of using Static Methods calls and Unhandled Exceptions


Recently one of my fellow developer had an issue of application crashing after making a new change.

Application keeps crashing and errors are not getting logged

While checking the Event Viewer found the following details

Event Type:      Error

Event Source:   .NET Runtime 2.0 Error Reporting

Event Category:            None

Event ID:          5000

Date:                4/18/2011

Time:                12:52:55 PM

User:                N/A

Computer:         XXXXX

Description:

EventType clr20r3, P1 dataprocess.exe, P2 1.0.0.0, P3 4da27055, P4 dataprocess, P5 1.0.0.0, P6 4da27055, P7 30, P8 b, P9 system.typeinitialization, P10 NIL.

Developer spent almost more than 5 hours to troubleshoot the problem.

Finally issue was due to the Static calls

public partial class Form1 : Form
{
  public static String _email_DevTeam = Configuration.GetValue("Email_DevTeam").ToString();   public static String _email_SentFrom = Configuration.GetValue("Email_SentFrom").ToString();   public static String _smtp = Configuration.GetValue("smtp").ToString();

Configuration.GetValue method didn’t had Exception handling and since Static calls being made before constructor or Form_Load() Event, Exception handling code in Form didn’t work.

Developers, Beware of using Static Functions !!!

Make sure all methods are having exception handling !!!

Author: Arunraj

I am a Microsoft Certified Technology Specialist (Database Developer). I work on SQL Server programming since SQL Server 7.0 specializes in SQL Server Programming and Performance Tuning and has 14 years of hands-on experience. I hold a Master Degree in Computer Applications. I am also part of NJSQL User Group and Northern New Jersey .Net User Group.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s