Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jack Gill 7 posts 77 karma points
    Apr 14, 2016 @ 15:43
    Jack Gill
    0

    Object reference not set to an instance of an object - Happens after cache reset

    Hey,

    I'm getting this error on my site:

    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

    Line 38:     else
    
    Line 39:     {
    
    Line 40:        @Html.Action("GetTTForm", "Membership", new { currentNodeId = Model.Id, currentUrl = library.NiceUrl(Model.Id), formAction = Model.FormAction })
    
    Line 41:    }
    

    On the member login page of the site, but it only seems to appear after the macro cache time is up which is currently an hour. If I delete my AppData folder and swap it with another version of my AppData folder and then republish the entire site - the problem page will work again for the next hour.

    I'm no where near an expert in umbraco, but I am finding this a very vague error - the controller it is referencing hasn't changed (to be clear this page on the site worked up with no problems until recently) and none of the ID's / Variables it operates have also changed.

    Is it at all possible it could be an IIS issue causing a crash when the cache is renewed?

    Any help would be fantastic as this has plagued me for all this week!

    Thanks,

  • Nicholas Westby 2054 posts 7103 karma points c-trib
    Apr 14, 2016 @ 16:18
    Nicholas Westby
    1

    Is there a stack trace to go along with the error message? There usually is in the Umbraco log file. Also, which version of Umbraco are you using?

    You might try splitting that line into a few different lines to help narrow down the issue. For example, perhaps Model is null sometimes for some reason. If you put the error on a different line (var modelId = Model.Id;), then you might get some info about the particular member access attempt that is causing the error.

    You could also try logging some variables to see if that helps narrow down the issue. That works like this: LogHelper.Info<SomeClass>("Some message.");

  • Jack Gill 7 posts 77 karma points
    Apr 14, 2016 @ 16:27
    Jack Gill
    0

    Thanks Nicholas,

    here is the stack trace to go with it:

    [NullReferenceException: Object reference not set to an instance of an object.]
       site.co.uk.logic.Controllers.MembershipController.GetTTForm(Int32 currentNodeId, String currentUrl, EnMyTTAction formAction) in path~\Controllers\MembershipController.cs:324
       lambda_method(Closure , ControllerBase , Object[] ) +247
       System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +280
       System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +35
       System.Web.Mvc.Async.<>c__DisplayClass42.<BeginInvokeSynchronousActionMethod>b__41() +33
       System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +42
       System.Web.Mvc.Async.<>c__DisplayClass39.<BeginInvokeActionMethodWithFilters>b__33() +80
       System.Web.Mvc.Async.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49() +386
       System.Web.Mvc.Async.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49() +386
       System.Web.Mvc.Async.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49() +386
       System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +42
       System.Web.Mvc.Async.<>c__DisplayClass2a.<BeginInvokeAction>b__20() +32
       System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) +185
       System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +38
       System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +27
       System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +22
       System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +53
       System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +22
       System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +38
       System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +42
       System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +22
       System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +38
       System.Web.Mvc.<>c__DisplayClass4.<Wrap>b__3() +15
       System.Web.Mvc.ServerExecuteHttpHandlerWrapper.Wrap(Func`1 func) +27
       System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride) +1737
    
    [HttpException (0x80004005): Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper'.]
       System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride) +2408
       System.Web.HttpServerUtility.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage) +131
       System.Web.HttpServerUtility.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm) +36
       System.Web.Mvc.Html.ChildActionExtensions.ActionHelper(HtmlHelper htmlHelper, String actionName, String controllerName, RouteValueDictionary routeValues, TextWriter textWriter) +595
       System.Web.Mvc.Html.ChildActionExtensions.Action(HtmlHelper htmlHelper, String actionName, String controllerName, RouteValueDictionary routeValues) +114
       ASP._Page_Views_MyTTPage_cshtml.Execute() in c:\inetpub\wwwroot\New folder\Views\MyTTPage.cshtml:40
       System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +253
       System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +147
       System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +107
       Umbraco.Core.Profiling.ProfilingView.Render(ViewContext viewContext, TextWriter writer) +232
       System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +375
       System.Web.Mvc.<>c__DisplayClass1a.<InvokeActionResultWithFilters>b__17() +31
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +437
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +437
       System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) +185
       System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +38
       System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +27
       System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +22
       System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +53
       System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +22
       System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +38
       System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +42
       System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +22
       System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +38
       System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +399
       System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +137
    

    I'll take a look at your other suggestions in the mean time,

    Thanks.

  • Nicholas Westby 2054 posts 7103 karma points c-trib
    Apr 14, 2016 @ 16:35
    Nicholas Westby
    1

    What does line 324 of MemberShipController look like?:

       site.co.uk.logic.Controllers.MembershipController.GetTTForm(Int32 currentNodeId, String currentUrl, EnMyTTAction formAction) in path~\Controllers\MembershipController.cs:324
    

    Based on this part of the stack trace, that's where the error is.

  • Jack Gill 7 posts 77 karma points
    Apr 14, 2016 @ 17:16
    Jack Gill
    0
    Line 321:      catch (Exception ex)
    Line 322:      {
    Line 323:           Log.Error("Error getting My TT form", ex);
    Line 324:           throw;
    Line 325:      }
    
  • Nicholas Westby 2054 posts 7103 karma points c-trib
    Apr 14, 2016 @ 17:32
    Nicholas Westby
    1

    Try removing that try/catch block. It seems to be preventing the stack trace from showing the true source of the exception.

    Alternatively, if you use LogHelper.Error<MembershipController>("Error getting My TT form", ex);, that should show the true stack trace to help you narrow down the error.

  • Jack Gill 7 posts 77 karma points
    Apr 14, 2016 @ 19:42
    Jack Gill
    0

    Ok, I removed the catch and getting the same error - but the stack trace now looks like this:

    [NullReferenceException: Object reference not set to an instance of an object.]
       site.co.uk.logic.Controllers.MembershipController.GetMyTTForm(Int32 currentNodeId, String currentUrl, EnMyTTAction formAction) in path~\Controllers\MembershipController.cs:272
       lambda_method(Closure , ControllerBase , Object[] ) +246
       System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +279
       System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +34
       System.Web.Mvc.Async.<>c__DisplayClass42.<BeginInvokeSynchronousActionMethod>b__41() +32
       System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +41
       System.Web.Mvc.Async.<>c__DisplayClass39.<BeginInvokeActionMethodWithFilters>b__33() +79
       System.Web.Mvc.Async.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49() +386
       System.Web.Mvc.Async.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49() +386
       System.Web.Mvc.Async.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49() +386
       System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +42
       System.Web.Mvc.Async.<>c__DisplayClass2a.<BeginInvokeAction>b__20() +32
       System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) +185
       System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +38
       System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +27
       System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +22
       System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +53
       System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +22
       System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +38
       System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +42
       System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +22
       System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +38
       System.Web.Mvc.<>c__DisplayClass4.<Wrap>b__3() +15
       System.Web.Mvc.ServerExecuteHttpHandlerWrapper.Wrap(Func`1 func) +27
       System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride) +1737
    
    [HttpException (0x80004005): Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper'.]
       System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride) +2408
       System.Web.HttpServerUtility.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage) +131
       System.Web.HttpServerUtility.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm) +36
       System.Web.Mvc.Html.ChildActionExtensions.ActionHelper(HtmlHelper htmlHelper, String actionName, String controllerName, RouteValueDictionary routeValues, TextWriter textWriter) +595
       System.Web.Mvc.Html.ChildActionExtensions.Action(HtmlHelper htmlHelper, String actionName, String controllerName, RouteValueDictionary routeValues) +114
       ASP._Page_Views_MyTTPage_cshtml.Execute() in c:\inetpub\wwwroot\New folder\Views\MyTTPage.cshtml:40
       System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +253
       System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +147
       System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +107
       Umbraco.Core.Profiling.ProfilingView.Render(ViewContext viewContext, TextWriter writer) +232
       System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +375
       System.Web.Mvc.<>c__DisplayClass1a.<InvokeActionResultWithFilters>b__17() +31
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +437
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +437
       System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) +185
       System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +38
       System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +27
       System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +22
       System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +53
       System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +22
       System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +38
       System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +42
       System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +22
       System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +38
       System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +399
       System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +137
    

    Line 272 is refering to this:

        public ActionResult GetMyTTForm(int currentNodeId, string currentUrl, Enums.EnMyTTAction formAction)
                {
                        var myTTPage = new CacheController().GetCachedMyTTPage(currentNodeId);
    
     Line 272:                   var model = new MembershipViewModel()
                        {
                            LoginPageUrl =
                                string.Format("{0}?{1}={2}", currentUrl, domain.Constants.QueryString.ACTION,
                                    Enums.EnMyTTAction.Login)
                            ,
                            RegisterPageUrl =
                                string.Format("{0}?{1}={2}", currentUrl, domain.Constants.QueryString.ACTION,
                                    Enums.EnMyTTAction.Register)
                            ,
                            ForgottenPasswordPageUrl =
                                string.Format("{0}?{1}={2}", currentUrl, domain.Constants.QueryString.ACTION,
                                    Enums.EnMyTTAction.ForgottenPassword)
                            ,
                            VisitorType = Session.GetVisitor().VisitorType
                            ,
                            LoginIntroductoryText = myTTPage.MyTTPageLoginIntroductoryText
                            ,
                            RegisterIntroductoryText = myTTPage.MyTTPageRegisterIntroductoryText
                            ,
                            ImageUrl = myTTPage.MyTTPageMainImage.Url
                        };
    
                        switch (formAction)
                        {
                            case Enums.EnMyTTAction.Login:
                                return View("~/Views/Partials/Membership/Login/_LoginForm.cshtml", model);
    
                            case Enums.EnMyTTAction.Register:
                                return View("~/Views/Partials/Membership/Register/_RegisterForm.cshtml", model);
    
                            case Enums.EnMyTTAction.ForgottenPassword:
                                return View("~/Views/Partials/Membership/ForgottenPassword/_ForgottenPasswordForm.cshtml", model);
    
                            case Enums.EnMyTTAction.ValidatePasswordResetCode:
                                return ValidatePasswordResetCode(currentNodeId, currentUrl, Request.QueryString[domain.Constants.QueryString.CODE]);
    
                            case Enums.EnMyTTAction.ResetPassword:
                                return View("~/Views/Partials/Membership/ResetPassword/_ResetPasswordForm.cshtml", model);
    
                            case Enums.EnMyTTAction.AuthenticatedResetPassword:
                                return AuthenticatedPasswordReset(currentNodeId, currentUrl);
    
                            default:
                                throw new NotImplementedException(formAction.ToString());
                        }
                }
    
  • Nicholas Westby 2054 posts 7103 karma points c-trib
    Apr 14, 2016 @ 19:48
    Nicholas Westby
    1

    Sounds like the error is somewhere in here (since this is all one line of code):

                        var model = new MembershipViewModel()
                        {
                            LoginPageUrl =
                                string.Format("{0}?{1}={2}", currentUrl, domain.Constants.QueryString.ACTION,
                                    Enums.EnMyTTAction.Login)
                            ,
                            RegisterPageUrl =
                                string.Format("{0}?{1}={2}", currentUrl, domain.Constants.QueryString.ACTION,
                                    Enums.EnMyTTAction.Register)
                            ,
                            ForgottenPasswordPageUrl =
                                string.Format("{0}?{1}={2}", currentUrl, domain.Constants.QueryString.ACTION,
                                    Enums.EnMyTTAction.ForgottenPassword)
                            ,
                            VisitorType = Session.GetVisitor().VisitorType
                            ,
                            LoginIntroductoryText = myTTPage.MyTTPageLoginIntroductoryText
                            ,
                            RegisterIntroductoryText = myTTPage.MyTTPageRegisterIntroductoryText
                            ,
                            ImageUrl = myTTPage.MyTTPageMainImage.Url
                        };
    

    If you break that into multiple lines, you should be able to figure out exactly which part is causing an issue. For example, you can create a variable like this:

    var loginPageUrl = string.Format("{0}?{1}={2}", currentUrl, domain.Constants.QueryString.ACTION, Enums.EnMyTTAction.Login);
    

    Then when constructing your MemberShipViewModel, you can assign the property to the variable value: LoginPageUrl = loginPageUrl.

    Next time you get an error, you'll have a better idea of what exactly is causing it.

    Alternatively, you can debug it locally by setting a breakpoint to see what's null. You can break on the error, the change the stack trace and inspect the variables. You can reduce the macro cache period so the error happens more frequently (rather than after an hour).

  • Jack Gill 7 posts 77 karma points
    Apr 15, 2016 @ 10:47
    Jack Gill
    0

    Thank you Nicolas so much for your help, I've managed to sort the issue. By splitting the line up like this:

        var myTTPage = new CacheController().GetCachedMyTTPage(currentNodeId);
    
        var model = new MembershipViewModel();
    
        var loginPageUrl = string.Format("{0}?{1}={2}", currentUrl, domain.Constants.QueryString.ACTION, Enums.EnMyTTAction.Login);
    
        var RegisterPageUrl = string.Format("{0}?{1}={2}", currentUrl, domain.Constants.QueryString.ACTION, Enums.EnMyTTAction.Register);
    
        var ForgottenPasswordPageUrl = string.Format("{0}?{1}={2}", currentUrl, domain.Constants.QueryString.ACTION, Enums.EnMyTTAction.ForgottenPassword);
    
        var VisitorType = Session.GetVisitor().VisitorType;
    
        var LoginIntroductoryText = myTTPage.MyTTPageLoginIntroductoryText;
    
        var RegisterIntroductoryText = myTTPage.MyTTPageRegisterIntroductoryText;
    
        var ImageUrl = myTTPage.MyTTPageMainImage.Url;
    

    I managed to pin point the issue to the last line:

     var ImageUrl = myTTPage.MyTTPageMainImage.Url;
    

    There wasn't an image selected in the back office causing the issue!

Please Sign in or register to post replies

Write your reply to:

Draft