Thursday, March 22, 2012

System.NullReferenceException: Object reference not set to an instance of an object.

I'm getting this error in my ASP.NET 2.0 web application when I fire following line in my code:

xmlWriter1.WriteRaw(Session["TempForm"].ToString());

Can someone tell me what am I missing ?

Does the session object TempForm exist?

I would change that code to the below and see if you still get the exception. If you do, then the issue is with xmlWriter1. If not, then it's your session variable.

string tempForm = Session["TempForm"] as string;

if (tempForm != null)
{
xmlWriter1.WriteRaw(tempForm);
}

HTH,
Ryan


Thanks Ryan, Its working now !!!

0 comments:

Post a Comment