我在以下代码行收到错误:对象引用未设置为对象的实例。为什么在测试null时收到此NullReferenceException错误?
if (Session["AutoCompleteCustomersPhone"] != null)
的代码完全块:
if (Session["AutoCompleteCustomersPhone"] != null)
earchCustomerPhone = true;
else
{
searchCustomerPhone =
bool.Parse(Session["AutoCompleteCustomersPhone"].ToString());
}
为什么,在空测试,我会收到这个错误?
很可能,'Session'本身是'null'。 – 2012-03-15 13:49:48
这段代码到底在哪里运行?它可能会给我们一个线索,为什么会话是空的... – greg84 2012-03-15 13:58:16
这是在一个ASMX Web服务,或WCF? – 2012-03-15 14:11:48