简体   繁体   中英

Weird Error: Object reference not set to an instance of an object

I get an error in live application sometimes.

Stack trace:

at Tool.User_RequestSender.Page_Load(Object sender, EventArgs e) in d:\\Site\\Tool\\User\\RequestSender.aspx.cs:line 72 at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) at System.Web.UI.Control.OnLoad(EventArgs e) at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

I tried again and again to run code om my machine but could not get same error.

Even i live code i get this issue once in while.

Page_Load Code in RequestSender.aspx.cs:

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() is as follows:

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();
            }
        }

    }

Error clearly states that smth is null during application execution.

To get any help you should either check for null values ( Request in LoadRequest() can be a good candidate), or, better solution, to modify your catch blog to log which parameter caused application to crash.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM