【发布时间】:2014-03-11 19:05:11
【问题描述】:
我试图创建一个新的 Customer 对象并从中检索 Cid 值,如下所示:
Line 32: Customer temp = new Customer();
Line 33: temp =(Customer)Session["customer"];
Line 34: int id = temp.Cid;
但我收到此错误:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object."
我也尝试过这样做:
int id = Convert.Toint(temp.Cid);
但它给了我同样的错误
【问题讨论】:
-
NullReferenceException的几乎所有情况都是相同的。请参阅“What is a NullReferenceException in .NET?”获取一些提示。
标签: c# asp.net session nullreferenceexception code-behind