Copied to clipboard

Flag this post as spam?

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


  • Martin Griffiths 826 posts 1269 karma points c-trib
    Jun 22, 2015 @ 09:46
    Martin Griffiths
    1

    UmbracoApplicationBase null reference exception....help needed.

    Can anyone help to point me in the general direction of being better able to locate where a controller and/or razor view/partial view exceptions as currently the log entry doesn't give enough detail through UmbracoApplicationBase.

    To be specific, I have a set of templates applied to a large number of pages and one of my templates is giving me a null reference exception as below.

    at System.Web.UI.ControlCollection.Add(Control child)
       at Umbraco.Web.UmbracoHelper.RenderMacro(macro m, IDictionary`2 parameters, page umbracoPage)
       at ASP._Page_Views_customRegistration_cshtml.

    I know why the macro is failing, but I don't know on what page its failing (nodeId) as there's the potential for this template to be applied in any number of places within large site. So I have no way of locating and fixing the issue accordingly.

    Thanks Martin

  • Barry Fogarty 493 posts 1129 karma points
    Jun 22, 2015 @ 10:19
    Barry Fogarty
    0

    Hi Martin,

    Wrap the offending code in your Macro in a try-catch block. Then you can add something like:

    LogHelper.Info(this.GetType(), "Error Message in here e.g. customRegistration fail, node ID = " + CurrentPage.Id); 
    

    Looking at the error it could be that it is occurring in the backoffice, in which case you may need to amend the above to correctly append the current node ID to the log message.

    NB to use logHelper you need to add

    using Umbraco.Core.Logging;
    

    at the top of your macro.

  • Martin Griffiths 826 posts 1269 karma points c-trib
    Jun 22, 2015 @ 10:21
    Martin Griffiths
    0

    Hi Barry

    Yea did exactly that! I hate it when I answer my own questions, and then feel a bit of a pleb for asking, oh well Mondays!

        try
        {
            @Umbraco.RenderMacro("umbracoContourRazorRenderForm", new { FormGuid = "[#contourForm]" })
    
        }
        catch (Exception ex)
        {
            LogHelper.Error(this.GetType(), "error at nodeId: " + CurrentPage.Id, ex);
        } 
    
  • Martin Griffiths 826 posts 1269 karma points c-trib
    Jun 22, 2015 @ 10:34
    Martin Griffiths
    0

    Hi Barry

    One thing I will say.... over the passing years, having stumbled through classic ASP and then moving into (what I thought at the time) the 'better' world of WebForms with compiled code behind, events and page controls. Going to MVC still at times feels like a step backwards.

    I love feel of total control within MVC; but to get so much power and flexibility back means you really discipline yourself with regards to where you put your code logic and how you control the flow of your application.

    I could throw in a Yoda joke, but i'll resist!

    M.

Please Sign in or register to post replies

Write your reply to:

Draft