发生对象引用错误 [英] Object reference error occured
问题描述
我在Windows 8服务器上通过文件托管到IIS。那个时候发生了错误。我无法确定问题所在。
对象参考未设置为对象实例
异常详细信息:System.NullReferenceException。
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?
推荐答案
使用下面的代码
string sourceFile = UploadIpFile。 PostedFile.FileName.ToString();
这不会返回Null参考
Use the below code
string sourceFile = UploadIpFile.PostedFile.FileName.ToString();
This will not return Null Reference
你好,
Hello,
对象引用未设置为对象的实例
Object Reference not set to an instance of an object
当您尝试引用的对象不在堆中时,会发生此错误。
何时分配对象在堆上???
:假设我说:
Class1 c = new Class1();
///请注意new关键字在堆上分配对象。
- 如果我不说new那么Class1是只是一个蓝色的印刷品,直到我说新才会实现。
- 如果你只是说:
Class1 c;
及以后代码中你说:
c。 some_method(); ///这不会工作,并且会在此行引发异常。
试用这段代码:
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:
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();
}
}
- 在你的情况下情况可能也类似。因此,您获得错误的行设置了一个断点(右键单击该行并设置断点)。
- 现在将鼠标悬停在对象/在该行之前的位置使用的对象(在该行中使用)。您将看到对象/对象为空。
- 现在使用new关键字重新初始化对象。这应该有所帮助。只需要一点调试就可以解决问题了。
谢谢,
-Rahul
();
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
这篇关于发生对象引用错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!