System.NullReferenceException Object reference not set to an instance of an object.
This error occurs in some specific .aspx pages,but iregularly.
Can you suggest some arounds for it and what are the causes for it??
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Sunny SharmaRank #223 · 11.1K reputationPosted Aug 2, 2013, 4:05 AM EDT
This is being caused by a server side operation.
You're trying to assign a variable with a null value. if it's happening some times then there may be some db operations or it completely depends on your logic laid out by you. Please share your code for more help.
Scott LysleRank #49 · 31K reputationPosted Aug 2, 2013, 4:09 AM EDT
For example, if I declare SomeClass myObject; and then I do something to it like myObject.GetDimension(); Since I never created the object (e.g., SomeClass myObject = new SomeClass();) the code will throw the exception.
Another example is in cases where you might populate an object using a method that might not always create an instance of that object. For example, SomeClass myObject = SomeClass.PopulateMyObject(); If PopulateMyObject does not always set the object to an instance of an object and then you try to do something with that object (say, myObject.ToString();, it will throw the exception.
The easiest way around seeing this error is to check to see if the object you tried to create is null before you attempt to perform any operations on it:
if(myObject != null)
{
// then do what you need to do with the object
}
else
{
// treat is like an error or do something else that will not throw the error
}
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 2, 2013, 4:11 AM EDT
Can you share that particular aspx code where this error is occurred?
Regards,
Iftikar
Akhil MittalRank #133 · 16.9K reputationPosted Aug 2, 2013, 7:10 AM EDT