我已经“继承”了一个包含以下代码行的项目:
objLibPharmacy.UserId = Guid.Parse(Session["GroupId"].ToString());
当我运行调试器时,我收到一条错误消息:
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.
部分堆栈跟踪如下:
[NullReferenceException: Object reference not set to an instance of an object.]
UserControl_wuc_Pharmacy.bindPharmacyPopUp()
bindPharmacyPopUp 如下:
private void bindPharmacyPopUp()
{
/******************Bind Pharmacy Popup*********************/
objLibPharmacy = new LibPharmacy();
objLibPharmacy.PharmacyId = 0;
objLibPharmacy.UserId = Guid.Parse(Session["GroupId"].ToString());
objclsPharmacy = new clsPharmacy();
objDs = objclsPharmacy.GetPharmacy(objLibPharmacy);
string strFilter = "";
if (objDs != null)
{
if (txtSearchPharmacy.Text != "")
strFilter = "PharmacyName like '%" + txtSearchPharmacy.Text + "%'";
DataView dv = objDs.Tables[0].DefaultView;
if (strFilter != "")
dv.RowFilter = strFilter;
Utility.bindGridview(dv.ToTable(), gvPharmacyList);
Utility.bindDDL(objDs.Tables[1], ddlPharmacyDetail, "Pharmacy");
//ViewState["PharmacyTable"] = objDs.Tables[0];
}
/*********************************************************/
}
是什么导致空引用?如何处理此类空引用以使调试无错误地运行?