Object reference not set to an instance of an object.. error

Posted by Parthibansk under ASP.NET on 11/28/2012 | Points: 10 | Views : 885 | Status : [Member] | Replies : 1
private int m_companyID;

protected void Page_Load(object sender, EventArgs e)
{
m_companyID = (int)Session["CompanyID"];
}

Object reference not set to an instance of an object..
i get this when i compile..




Responses

Posted by: aswinialuri-19361 on: 11/28/2012 [Member] Starter | Points: 25

Up
0
Down
hi
The reason is that the program is trying to access a member of a reference type variable which is set to null.
or
This error happens when you try to use a property or call a method of an object that is null.

A simple use of Visual studio DEBUGGER can tell you the object because of which it is happening. Just look at the stack trace and put a debugger on that line. Check the objects of that line and see if any one is null and you are trying to use that objects property. Handle the same.



thanks

Mark as Answer if it helps you
Thanks&Regards
Aswini Aluri

Parthibansk, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response