How to handel NULL referance
-
Hi All I have a web application in asp.net 1.1 and sql server 2000, it was running alright previously, but for some weeks users are reporting that they are facing error. In the application whenever any error comes , user is being redirected to an error page and the actual error message comes to our(the programmers) email. The error message is very long but I'll mention the important part:- In the email :- System.NullReferenceException: Object reference not set to an instance of an object. at CBSolutions.ETH.Web.newlook.VSPage.LoadPageStateFromPersistenceMedium() at System.Web.UI.Page.LoadAllState() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) The code for function CBSolutions.ETH.Web.newlook.VSPage.LoadPageStateFromPersistenceMedium() is :- protected override object LoadPageStateFromPersistenceMedium() { if (ConfigurationSettings.AppSettings["ServerSideViewState"].ToUpper() == "TRUE") { string VSKey; VSKey = Request.Form["__VIEWSTATE_KEY"]; if (!(VSKey.StartsWith("VIEWSTATE_"))) { throw new Exception("Invalid VIEWSTATE Key: " + VSKey); } if (ConfigurationSettings.AppSettings["ViewStateStore"].ToUpper() == "CACHE") { return Cache[VSKey]; } else { DataTable VsDataTable; DataRow DbRow; VsDataTable = ((DataTable) Session["__VSDataTable"]); DbRow = VsDataTable.Rows.Find(VSKey); // if (DbRow!=null) // { // throw new Exception("VIEWStateKey not Found. Consider increasing the ViewStateTableSize parameter on Web.Config file."); // } return DbRow["VsData"]; } } else { return base.LoadPageStateFromPersistenceMedium(); } } Also in the Event Viewer application log, the following warning appears:- Event code: 3005 Event message: An unhandled exception has occurred. . . . . . Thread information: Thread ID: 6 Thread account name: NT AUTHORITY\NETWORK SERVICE Is impersonating: False Stack trace: at System.Web.HttpServerUtility.MapPath(String path) at ETH.Global.Session_End(Object sender, EventArgs e) Here ETH.Global.Session_End(Object sender, EventArgs e) is written in Global.asax which is as follows:- protected void Session_End(Object sender, EventArgs e) { //clean up temporary files string[] files = System.IO.Directory.GetFiles(Server.MapPath("Files/"),"WF-" + Session.SessionID + "*.*");
-
Hi All I have a web application in asp.net 1.1 and sql server 2000, it was running alright previously, but for some weeks users are reporting that they are facing error. In the application whenever any error comes , user is being redirected to an error page and the actual error message comes to our(the programmers) email. The error message is very long but I'll mention the important part:- In the email :- System.NullReferenceException: Object reference not set to an instance of an object. at CBSolutions.ETH.Web.newlook.VSPage.LoadPageStateFromPersistenceMedium() at System.Web.UI.Page.LoadAllState() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) The code for function CBSolutions.ETH.Web.newlook.VSPage.LoadPageStateFromPersistenceMedium() is :- protected override object LoadPageStateFromPersistenceMedium() { if (ConfigurationSettings.AppSettings["ServerSideViewState"].ToUpper() == "TRUE") { string VSKey; VSKey = Request.Form["__VIEWSTATE_KEY"]; if (!(VSKey.StartsWith("VIEWSTATE_"))) { throw new Exception("Invalid VIEWSTATE Key: " + VSKey); } if (ConfigurationSettings.AppSettings["ViewStateStore"].ToUpper() == "CACHE") { return Cache[VSKey]; } else { DataTable VsDataTable; DataRow DbRow; VsDataTable = ((DataTable) Session["__VSDataTable"]); DbRow = VsDataTable.Rows.Find(VSKey); // if (DbRow!=null) // { // throw new Exception("VIEWStateKey not Found. Consider increasing the ViewStateTableSize parameter on Web.Config file."); // } return DbRow["VsData"]; } } else { return base.LoadPageStateFromPersistenceMedium(); } } Also in the Event Viewer application log, the following warning appears:- Event code: 3005 Event message: An unhandled exception has occurred. . . . . . Thread information: Thread ID: 6 Thread account name: NT AUTHORITY\NETWORK SERVICE Is impersonating: False Stack trace: at System.Web.HttpServerUtility.MapPath(String path) at ETH.Global.Session_End(Object sender, EventArgs e) Here ETH.Global.Session_End(Object sender, EventArgs e) is written in Global.asax which is as follows:- protected void Session_End(Object sender, EventArgs e) { //clean up temporary files string[] files = System.IO.Directory.GetFiles(Server.MapPath("Files/"),"WF-" + Session.SessionID + "*.*");
As the exception says,you must be eccesing some object that is not instantiated properly.So debug it and find which object is not getting created properly.
Cheers!! Brij Check My Latest Article
-
Hi All I have a web application in asp.net 1.1 and sql server 2000, it was running alright previously, but for some weeks users are reporting that they are facing error. In the application whenever any error comes , user is being redirected to an error page and the actual error message comes to our(the programmers) email. The error message is very long but I'll mention the important part:- In the email :- System.NullReferenceException: Object reference not set to an instance of an object. at CBSolutions.ETH.Web.newlook.VSPage.LoadPageStateFromPersistenceMedium() at System.Web.UI.Page.LoadAllState() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) The code for function CBSolutions.ETH.Web.newlook.VSPage.LoadPageStateFromPersistenceMedium() is :- protected override object LoadPageStateFromPersistenceMedium() { if (ConfigurationSettings.AppSettings["ServerSideViewState"].ToUpper() == "TRUE") { string VSKey; VSKey = Request.Form["__VIEWSTATE_KEY"]; if (!(VSKey.StartsWith("VIEWSTATE_"))) { throw new Exception("Invalid VIEWSTATE Key: " + VSKey); } if (ConfigurationSettings.AppSettings["ViewStateStore"].ToUpper() == "CACHE") { return Cache[VSKey]; } else { DataTable VsDataTable; DataRow DbRow; VsDataTable = ((DataTable) Session["__VSDataTable"]); DbRow = VsDataTable.Rows.Find(VSKey); // if (DbRow!=null) // { // throw new Exception("VIEWStateKey not Found. Consider increasing the ViewStateTableSize parameter on Web.Config file."); // } return DbRow["VsData"]; } } else { return base.LoadPageStateFromPersistenceMedium(); } } Also in the Event Viewer application log, the following warning appears:- Event code: 3005 Event message: An unhandled exception has occurred. . . . . . Thread information: Thread ID: 6 Thread account name: NT AUTHORITY\NETWORK SERVICE Is impersonating: False Stack trace: at System.Web.HttpServerUtility.MapPath(String path) at ETH.Global.Session_End(Object sender, EventArgs e) Here ETH.Global.Session_End(Object sender, EventArgs e) is written in Global.asax which is as follows:- protected void Session_End(Object sender, EventArgs e) { //clean up temporary files string[] files = System.IO.Directory.GetFiles(Server.MapPath("Files/"),"WF-" + Session.SessionID + "*.*");
Good Question but when you post in CP use the < pre > tags to format your code, i would like to help , but i loose interest because your code is not formated well
int i=0;
try to format it and we will answer
Vuyiswa Maseko, Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers." C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.somee.com http://www.vuyiswamaseko.tiyaneProperties.co.za vuyiswa@its.co.za http://www.itsabacus.co.za/itsabacus/