I am Trying to access one of my page say staffs.aspx and getting the following error/ exception.
Error Message: Object reference not set to an instance of an object.
Stack Trace: at BasePage.LoadPageStateFromPersistenceMedium() in c:\TeamCity\buildAgent\work\895f95277d6888cc\FrontEnd\App_Code\BasePage.cs:line 17 at System.Web.UI.Page.LoadAllState() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Though, it runs fine on my system but my client is facing problem to access this page.
Here Is The piece of code ...
protected override object LoadPageStateFromPersistenceMedium()
{
System.Web.UI.PageStatePersister pageStatePersister = this.PageStatePersister;
pageStatePersister.Load();
byte[] bytes = Convert.FromBase64String(pageStatePersister.ViewState.ToString());//Line 17
bytes = Common.Decompress(bytes);
LosFormatter losFormatter = new LosFormatter();
Object viewState = losFormatter.Deserialize(Convert.ToBase64String(bytes));
return new Pair(pageStatePersister.ControlState, viewState);
}
here is the code for SavePageStateToPersistenceMedium :
protected override void SavePageStateToPersistenceMedium(object state)
{
Pair pair;
System.Web.UI.PageStatePersister pageStatePersister = this.PageStatePersister;
Object viewState;
if (state is Pair)
{
pair = ((Pair)state);
pageStatePersister.ControlState = pair.First;
viewState = pair.Second;
}
else
viewState = state;
LosFormatter losFormatter = new LosFormatter();
StringWriter stringWriter = new StringWriter();
losFormatter.Serialize(stringWriter, viewState);
byte[] bytes = Convert.FromBase64String(stringWriter.ToString());
bytes = Common.Compress(bytes);
pageStatePersister.ViewState = Convert.ToBase64String(bytes);
pageStatePersister.Save();
}
FYI : I thought may be its a browser issue so i tried this page in multiple browsers , and all worked fine for me. worked with cache clear , database calls and redirections to the suspected page. but got no error. So I am unable to understand what is producing a null object.
Thanks!