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.
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.
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.
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.
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
Hi Martin,
Wrap the offending code in your Macro in a try-catch block. Then you can add something like:
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
at the top of your macro.
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!
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.
is working on a reply...