By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,181 Members | 1,192 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,181 IT Pros & Developers. It's quick & easy.

I have got a warning in event viewer

P: 11
I have got the warning in event viewer when i wrote the code in global.asax session_end().
When the user sessions time out, the Session_End event fires successfully.But i got the waring in event viewer.


My Waring is


Expand|Select|Wrap|Line Numbers
  1. Event code: 3005 
  2. Event message: An unhandled exception has occurred. 
  3. Event time: 8/14/2009 3:04:16 PM 
  4. Event time (UTC): 8/14/2009 9:34:16 AM 
  5. Event ID: 981e4e58a2cd43f293827e9350c15da9 
  6. Event sequence: 731 
  7. Event occurrence: 2 
  8. Event detail code: 0 
  9.  
  10. Application information: 
  11.     Application domain: 6a76b598-9-128947141739218750 
  12.     Trust level: Full 
  13.     Application Virtual Path: /Sample
  14.     Application Path: C:\Sample\ 
  15.     Machine name: MachineName
  16.  
  17. Process information: 
  18.     Process ID: 3928 
  19.     Process name: WebDev.WebServer.EXE 
  20.     Account name: MachineName\Administrator 
  21.  
  22. Exception information: 
  23.     Exception type: NullReferenceException 
  24.     Exception message: Object reference not set to an instance of an object. 
  25.  
  26. Request information: 
  27.     Request URL:  
  28.     Request path:  
  29.     User host address:  
  30.     User:  
  31.     Is authenticated: False 
  32.     Authentication Type:  
  33.     Thread account name: MachineName\Administrator 
  34.  
  35. Thread information: 
  36.     Thread ID: 4 
  37.     Thread account name: MachineName\Administrator 
  38.     Is impersonating: False 
  39.     Stack trace:    at ASP.global_asax.Session_End(Object sender, EventArgs e) in c:\Sample\Global.asax:line 80

My session_end() code is

Expand|Select|Wrap|Line Numbers
  1.  void Session_End(object sender, EventArgs e)
  2.     {
  3.         // Code that runs when a session ends. 
  4.  
  5.         // Note: The Session_End event is raised only when the sessionstate mode
  6.         // is set to InProc in the Web.config file. If session mode is set to StateServer
  7.         // or SQLServer, the event is not raised.        
  8.  
  9.         string domainName = AppDomain.CurrentDomain.BaseDirectory.ToString();
  10.         string strDirName = domainName.Replace("bin\\Debug\\", "");
  11.  
  12.         string enableLogging = ConfigurationSettings.AppSettings.Get("EnableSessionLog");
  13.  
  14.         if (enableLogging.ToLower() == "true")
  15.         {
  16.  
  17.             TextWriter tw = new StreamWriter(strDirName + "Log Files\\SessionLog.txt", true);
  18.             if (Session["portalID"] != null)
  19.             {
  20.                 tw.WriteLine("Session Ends");
  21.                 tw.WriteLine(DateTime.Now + "  SessionTimedout SessionID = " + Session.SessionID);
  22.                 tw.WriteLine(DateTime.Now + "  SessionTimedout UserName = " + Session["session_username"].ToString());
  23.                 tw.WriteLine(DateTime.Now + "  SessionTimedout PortalID = " + Session["portalID"].ToString());
  24.                 tw.WriteLine(DateTime.Now + "  SessionTimedout PatientID = " + Session["patientID"].ToString());
  25.             }
  26.             tw.Close();
  27.  
  28.         }
  29.     }      
Please tell me how to avoid this problem
Aug 14 '09 #1
Share this Question
Share on Google+
1 Reply


tlhintoq
Expert 2.5K+
P: 3,525
Please tell me how to avoid this problem
Expand|Select|Wrap|Line Numbers
  1. Exception information: 
  2.     Exception type: NullReferenceException 
  3.     Exception message: Object reference not set to an instance of an object. 
  4.  
You need to initialize all your objects so they are not null and actually are instances of objects.

The debugger should have halted on the offending line.
You can then use the object/variables viewer to see what each object is set to. Or you can hover the mouse over each object to see in the tooltip what it's value is... keep hunting until you find the nulls.
Aug 14 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.