I have got a warning in event viewer

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anithaapr05
    New Member
    • Aug 2009
    • 11

    I have got a warning in event viewer

    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.Bu t i got the waring in event viewer.


    My Waring is


    Code:
    Event code: 3005 
    Event message: An unhandled exception has occurred. 
    Event time: 8/14/2009 3:04:16 PM 
    Event time (UTC): 8/14/2009 9:34:16 AM 
    Event ID: 981e4e58a2cd43f293827e9350c15da9 
    Event sequence: 731 
    Event occurrence: 2 
    Event detail code: 0 
     
    Application information: 
        Application domain: 6a76b598-9-128947141739218750 
        Trust level: Full 
        Application Virtual Path: /Sample
        Application Path: C:\Sample\ 
        Machine name: MachineName
     
    Process information: 
        Process ID: 3928 
        Process name: WebDev.WebServer.EXE 
        Account name: MachineName\Administrator 
     
    Exception information: 
        Exception type: NullReferenceException 
        Exception message: Object reference not set to an instance of an object. 
     
    Request information: 
        Request URL:  
        Request path:  
        User host address:  
        User:  
        Is authenticated: False 
        Authentication Type:  
        Thread account name: MachineName\Administrator 
     
    Thread information: 
        Thread ID: 4 
        Thread account name: MachineName\Administrator 
        Is impersonating: False 
        Stack trace:    at ASP.global_asax.Session_End(Object sender, EventArgs e) in c:\Sample\Global.asax:line 80

    My session_end() code is

    Code:
     void Session_End(object sender, EventArgs e)
        {
            // Code that runs when a session ends. 
    
            // Note: The Session_End event is raised only when the sessionstate mode
            // is set to InProc in the Web.config file. If session mode is set to StateServer
            // or SQLServer, the event is not raised.        
    
            string domainName = AppDomain.CurrentDomain.BaseDirectory.ToString();
            string strDirName = domainName.Replace("bin\\Debug\\", "");
    
            string enableLogging = ConfigurationSettings.AppSettings.Get("EnableSessionLog");
    
            if (enableLogging.ToLower() == "true")
            {
    
                TextWriter tw = new StreamWriter(strDirName + "Log Files\\SessionLog.txt", true);
                if (Session["portalID"] != null)
                {
                    tw.WriteLine("Session Ends");
                    tw.WriteLine(DateTime.Now + "  SessionTimedout SessionID = " + Session.SessionID);
                    tw.WriteLine(DateTime.Now + "  SessionTimedout UserName = " + Session["session_username"].ToString());
                    tw.WriteLine(DateTime.Now + "  SessionTimedout PortalID = " + Session["portalID"].ToString());
                    tw.WriteLine(DateTime.Now + "  SessionTimedout PatientID = " + Session["patientID"].ToString());
                }
                tw.Close();
    
            }
        }
    Please tell me how to avoid this problem
    Last edited by tlhintoq; Aug 14 '09, 10:29 AM. Reason: [CODE] ...your code goes here... [/CODE] tags added
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    Please tell me how to avoid this problem
    Code:
    Exception information: 
        Exception type: NullReferenceException 
        Exception message: Object reference not set to an instance of an object.
    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.

    Comment

    Working...