C# 奇怪的错误:对象引用未设置为对象的实例
我有时会在实时应用程序中出错 堆栈跟踪: 在中的Tool.User\u RequestSender.Page\u加载(对象发送方,事件参数e) d:\Site\Tool\User\RequestSender.aspx.cs:第72行 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp,对象 o、 对象t,事件参数e)在 System.Web.Util.CallEventHandlerDelegateProxy.Callback(对象发送方, 在System.Web.UI.Control.OnLoad(EventArgs e)的 System.Web.UI.Control.LoadRecursive()位于 System.Web.UI.Page.ProcessRequestMain(布尔值 IncludeStages前同步点,布尔值IncludeStages后同步点) 我一次又一次地尝试在我的机器上运行代码,但没有得到相同的错误 即使我是活代码,我偶尔也会遇到这个问题 页面\ RequestSender.aspx.cs中的加载代码:C# 奇怪的错误:对象引用未设置为对象的实例,c#,asp.net,C#,Asp.net,我有时会在实时应用程序中出错 堆栈跟踪: 在中的Tool.User\u RequestSender.Page\u加载(对象发送方,事件参数e) d:\Site\Tool\User\RequestSender.aspx.cs:第72行 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp,对象 o、 对象t,事件参数e)在 System.Web.Util.CallEventHandlerDelegateProxy.Callback
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (!IsPostBack)
{
this.LoadRequest();
}
}
catch (CustomException ex)
{
this.ShowMessage(ex.Message);
}
catch (Exception ex)
{
throw ex;
}
}
LoadRequest()如下所示:
private void LoadRequest()
{
Credential credential;
if (
!string.IsNullOrEmpty(Request["typeOfrequest"]) &&
!string.IsNullOrEmpty(Request["empUserId"]) &&
!string.IsNullOrEmpty(Request["applicationId"])
)
{
// Get details of credentials
credential = (new RequestManager()).GetCredential(this.EmpUserId, this.ApplicationId, (int)this.TypeOfrequest);
this.applicaionRequest = new Request
{
RequestType = this.TypeOfrequest,
RequestStatus = Enumerations.RequestStatus.Sent,
Application = credential.Application,
EmpUserId = credential.EmpUserId,
EmployeeId = credential.EmployeeId,
Username = credential.Username,
SenderAddress = Security.CurrentUser.Details.EmailAddress,
ReceiverAddress = (new Datastore.RequestStore()).GetReceiverAddress((int)this.TypeOfrequest, this.ApplicationId),
AddedBy = Security.CurrentUser.Details.UserId
};
ucSendRequest.ApplicationRequest = applicaionRequest;
}
else
{
Response.Write("Invalid request!");
Response.End();
}
}
}
错误明确指出在应用程序执行期间smth为
null
要获得任何帮助,您应该检查
null
值(LoadRequest()
中的Request
可能是一个很好的候选者),或者,更好的解决方案是,修改catch日志,记录哪个参数导致了应用程序崩溃。事实是您有一个catch(Exception ex){throw ex;}
掩盖了原始原因。去掉那个catch块,你就会更好地了解发生了什么。ucSendRequest是什么?例如…但我无法在我的机器上获得错误…即使我删除了try-catch,我的机器上也不会再出现任何错误或问题…@mihirj:这是用户控制捕获异常,然后发出“throw-ex”替换stacktrace,这意味着您不太可能找到异常的实际来源。如果您需要重新显示已捕获的异常,请在catch块内单独使用“throw”。如果在你的接球挡中除了投掷之外什么都没有,那么你一开始就不需要接球挡。