System.NullReferenceException: Object reference not set to an instance of an object.异常
我的程序在本机运行正常,但发布到服务器时,提交信息的时候有时会提示下面的错误:Server Error in '/' Application.
--------------------------------------------------------------------------------
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.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
UserControl_friend.bntSubmit_Click(Object sender, ImageClickEventArgs e) +2036
System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e) +105
System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument) +115
System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102
调试也没有发现任何的异常,,而且在本地用iis也都正常,,,但是在服务器上面提交信息的时候,第一次可以正常,再提交(当然信息也是另外输入的)的时候就出现异常了
各位大虾帮帮忙啊。。。小女子先谢谢了。。。
--------------------编程问答-------------------- 怎么都没有人来的:( --------------------编程问答-------------------- 检查你的UserControl_friend.bntSubmit_Click(Object sender, ImageClickEventArgs e)中的代码。
应该在这个文件的第2036行,看看那个变量是null的。
或者把这个函数贴出来吧。 --------------------编程问答-------------------- 这个文件没有那么多行啊。。。最后一个字符也是第197行,没有第2036行
protected void bntSubmit_Click(object sender, ImageClickEventArgs e)
{
if (!Page.IsValid)
{
return;
}
if (Request.Cookies["CheckCode"] == null)
{
return;
}
if (String.Compare(Request.Cookies["CheckCode"].Value, this.txtDatabase.Value, true) != 0)
{
lblMsg.Visible = true;
lblMsg.Text = "验证码不正确!";
return;
}
if (txtMap.Value.Trim() != "")
{
if (GetUploadImgs(txtMap) == null)
{
return;
}
}
if (Request.QueryString["ID"] != null && Request.QueryString["ID"] != "")
{
string title = txtTitle.Value.Trim();
string self = txtDesc.Value.Trim();
string email = txtEmail.Value.Trim();
string name = txtName.Value.Trim();
string tel = txtTel.Value.Trim();
string other = txtOther.Value.Trim();
string picpath = GetUploadImgsUrl();
if (picpath != "0")
{
string[] cols = { "title", "self", "email", "name", "tel", "other", "picpath", "createtime" };
string[] values = { title, self, email, name, tel, other, picpath, DateTime.Now.ToString() };
service.UpdateFriend(cols, values, Request.QueryString["ID"]);
lblMsg.Visible = true;
lblMsg.Text = "保存成功!";
}
else
{
string[] cols = { "title", "self", "email", "name", "tel", "other", "createtime" };
string[] values = { title, self, email, name, tel, other, DateTime.Now.ToString() };
service.UpdateFriend(cols, values, Request.QueryString["ID"]);
lblMsg.Visible = true;
lblMsg.Text = "保存成功!";
}
}
else
{
Entities.friend friend = EntityFactory<Entities.friend>.CreateObject();
friend.title = txtTitle.Value.Trim();
friend.picpath = GetUploadImgsUrl();
DataTable citydt = service.FindArea(" and id=" + Request.QueryString["areaid"]).Tables[0];
friend.city = int.Parse(GetRoots(citydt, 1));
DataTable areadt = service.FindArea(" and parentid=" + GetRoots(citydt, 1)).Tables[0];
if (areadt.Rows.Count > 0)
{
friend.area = int.Parse(areadt.Rows[0]["id"].ToString());
DataTable streetdt = service.FindArea(" and parentid=" + areadt.Rows[0]["id"].ToString()).Tables[0];
if (streetdt.Rows.Count > 0)
{
friend.street = int.Parse(streetdt.Rows[0]["id"].ToString());
}
}
friend.categoryid = int.Parse(Request.QueryString["categoryid"]);
friend.createid = int.Parse(Session["Userid"].ToString() == "" ? "0" : Session["Userid"].ToString());
friend.createtime = DateTime.Now;
friend.email = txtEmail.Value.Trim();
friend.name = txtName.Value.Trim();
friend.other = txtOther.Value.Trim();
friend.self = txtDesc.Value.Trim();
friend.tel = txtTel.Value.Trim();
service.InsertFriend(friend);
lblMsg.Visible = true;
lblMsg.Text = "保存成功!";
}
} --------------------编程问答-------------------- 有没有人啊 --------------------编程问答-------------------- 反正你的这段代码又不长,你就一个一个变量看看,哪个变量是null不就知道哪错了么 --------------------编程问答-------------------- 先单步调看哪句报错 --------------------编程问答-------------------- 单步调试,看那个变量为null --------------------编程问答-------------------- 调试是没有任何异常的。。。。
发布之后在在本地的iis运行也没有任何问题。。。
但是放到服务器上就出现的这样的异常。。。
--------------------编程问答-------------------- compilation debug="true"
或上服务器 运行,就能报出错误在哪里 --------------------编程问答-------------------- 楼主你是怎么解决这个问题的?
补充:.NET技术 , C#