Click here to Skip to main content
15,921,276 members
Please Sign up or sign in to vote.
1.80/5 (2 votes)
See more:
Hi,

I am hosted by file to IIS on Windows 8 server. That time the error occured. I can't identify what is the problem.

Object Reference not set to an instance of an object

Exception Details:System.NullReferenceException.

Stack trace:

[Null Referrence Exception:Object reference not set to an instance of an object]
System.Collects.ObjectModel.Collection.1.Clear()+46
Inttelix.dataCollection.DALCollectionbase'2.BeginLoadData()+353
Inttelix.dataCollection.DALCollectionbase'2.LoadFromDBInternal(IDbTransaction Trnasaction,String Wherecondition,String OrderBy,Object[] parameters)+205




This error will come only on particular server only. In other systems it is working. Anybody can guess what is the problem?
Posted
Updated 19-Jan-14 23:57pm
v2
Comments
Richard MacCutchan 20-Jan-14 5:05am    
You have a reference somewhere that does not point to anything. That is to say, you are using a reference without first checking that it is valid. Only by looking at the source code can you find out why this occurs.
JoCodes 20-Jan-14 5:59am    
NullReferenceException is very generic exception. You should debug and find where exactly and which line it occurs so that it can be easily rectified.
[no name] 20-Jan-14 7:13am    
Hi...devausha.
I think,u r getting empty data(no data) from data base!.
devausha 21-Jan-14 1:29am    
Hi all, actually in my developing system itself it is working, there are no error will come. After I host itinto client system only this issue happens, I put try catch block also. But it is not mentioned when that issue is happens.

Use the below code

string sourceFile = UploadIpFile.PostedFile.FileName.ToString();

This will not return Null Reference
 
Share this answer
 
Hello,

Quote:
Object Reference not set to an instance of an object


This error occurs when the object you are trying to reference is not present in the heap.

When is an object allocated on the heap???

: Suppose i say:

Class1 c = new Class1();
///Please note that the "new" keyword allocates the object on the heap.

- If i dont say "new" then "Class1" is just a blue print it does not come into realization until i say "new".

- If you simply say:

Class1 c;

and later in your code you say :

c.some_method();///this wont work and an exception will be thrown at this line.


Try out this code:

C#
class Program
   {
       public void method()
       {
           Console.WriteLine("hello");

       }

       static void Main(string[] args)
       {
           Program p = null;
           p.method(); ////Exception will be thrown at this line. 
           Console.ReadLine();

       }
   }

();
Console.ReadLine();

}
}


- In your case also the situation may be something similar. So the line where you get an error set a break point(right click that line and set a break point).

- Now hover your the mouse to the object/objects(used in that line) used in places before that line. You will see that the object/objects are null.

- Now reinitialize the objects by using the "new" keyword. This should help. Just a little debugging and the problem should go.

Thanks,
-Rahul
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900