Object reference not set to an instance of an object error
Object reference not set to an instance of an object error in a line - strUserSanctionLevel = Session["UserSanctionLevel"].ToString();
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Shubham KumarPosted Apr 10, 2015, 8:00 AM
"Object reference not set to an instance of an object" means your object's instance is not made and you are trying to perform operation on it just first create your instance :) and you will get the answer
Khargesh RajputPosted Apr 10, 2015, 6:28 AM
if(Session["UserSanctionLevel"]!=null)
{
strUserSanctionLevel = Session["UserSanctionLevel"].ToString();
}
Akhil GargPosted Apr 10, 2015, 6:26 AM
First Initialize
String strUserSanctionLevel=new String();
then write
strUserSanctionLevel = Session["UserSanctionLevel"].ToString();
or Session["UserSanctionLevel"] is null so use Convert.ToString(Session["UserSanctionLevel"]) instead of direct ToString();