Copied to clipboard

Flag this post as spam?

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


  • Eli Estes 9 posts 119 karma points
    Oct 23, 2020 @ 01:03
    Eli Estes
    0

    Umbraco Cloud troubleshoot null reference exception on homepage

    The homepage on our umbraco cloud site started throwing exceptions this afternoon. No one has made any changes (code or backoffice) for about two months. We just started getting a null reference exception on some razor code in a template all of a sudden. I tried everything I could think of: I redeployed the site, republished the entire site, I even removed all razor code from the template, but I'm still getting the errors. I can't restore to my local (I assume because of the error), so I'm having to modify the template directly from the backoffice. I tried the live chat, but they didn't find anything. Not sure what to do at this point. Is there even anything I can do?

  • Marc Goodson 2138 posts 14321 karma points MVP 8x c-trib
    Oct 25, 2020 @ 10:49
    Marc Goodson
    0

    Hi Eli

    Can you provide details of the stack trace for the error, and the error message?

    Can you provide the code for the homepage template?

    Are other pages, beyond the homepage ok?

    Do you use Modelsbuilder - and have the Models been regenerated?

    Which version of Umbraco is this?

    regards

    marc

  • Eli Estes 9 posts 119 karma points
    Oct 26, 2020 @ 15:25
    Eli Estes
    100

    Hi Marc,

    Thank you for responding. We were able to resolve the issue over the weekend.

    We found the null reference exception, but it was on a different template than what was being logged. Since I was unable to pull down the content to my local for troubleshooting, the Umbraco support person copied the home node in the content tree so that we could delete content in the copy without losing it. Once we completely removed the content related to the template throwing the exception, we started seeing a new exception on another template. When we looked into that template, we did find a null reference exception. Once that was fixed, the page started working again.

    I talked to our client that manages the content and it sounded like they did make a change on that day, but I can't find any record of it in the audit history for that page. I'm still very confused about why there's no audit history and why the exception was showing up on another template, but we're running Umbraco 7.10, so maybe this is not an issue on newer versions. Even though this is already resolved, I'll document the errors and code in case this is beneficial to anyone going forward:

    Here is the error message:

    Message:
    An unhandled exception occurred
    
    
    Exception:
    System.NullReferenceException: Object reference not set to an instance of an object.
       at ASP._Page_Views_graphicWithDetails_cshtml.Execute() in c:\home\site\wwwroot\Views\GraphicWithDetails.cshtml:line 23
       at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
       at System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
       ...
    

    Here is the template code. It's a partial used by a nested content doctype:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage<ContentModels.GraphicWithDetails>
    @using ContentModels = Umbraco.Web.PublishedContentModels;
    @{
        Layout = null;
    
        var cssClass = Ctl.Core.Helpers.NestedContentViewCssClass(Model.Content);
        var content = Model.Content.Content;
        if(content == null)
        {
            content = new HtmlString("");
        }
    }
    
    
    <div class="container pad @cssClass">
        @if (Model.Content.HasValue("Headline"))
        {
            <h2 class="section_headline">@Model.Content.Headline</h2>
        }
    
        <div class="graphic_with_details reverse_on_small">
            <div class="details right_spacing">
                @Html.Raw(content)
            </div>
    
            <div class="graphic">
                <img src="@Model.Content.Image.Url" alt="@Model.Content.Image.GetPropertyValue("alt")">
            </div>
        </div>
    </div>
    

    Other pages are/were working

    We use Modelsbuilder, and I had regenerated models.

    Umbraco version is 7.10.6

  • Marc Goodson 2138 posts 14321 karma points MVP 8x c-trib
    Oct 26, 2020 @ 17:38
    Marc Goodson
    0

    Hi Eli

    Glad you have it all back up and running.

    It's difficult to say for sure without the line numbers!

    But this line:

     <img src="@Model.Content.Image.Url" alt="@Model.Content.Image.GetPropertyValue("alt")">
    

    Would throw an error if for some reason the Image wasn't picked for the content item, (or if the Examine Internal Index were corrupted), it can be good to check if the image is null first before writing out it's Url property eg:

    @if (Model.Content.Image!=null){
         <img src="@Model.Content.Image.Url" alt="@Model.Content.Image.GetPropertyValue("alt")">
    }
    

    but maybe it was something else entirely!

    regards

    Marc

Please Sign in or register to post replies

Write your reply to:

Draft