Hoping I'm just doing something silly and I haven't had enough coffee to work out what's going wrong.
In short, I have a navigation partial where I am looking up the sites home node, and then grabbing its children:
Home home = Umbraco.TypedContentAtXPath("//home").Select(x => new Home(x)).FirstOrDefault();
IEnumerable<IPublishedContent> pages = home.Children;
That seems to be pretty good to me. And it works lovely on any child pages of the home page. However, it throws a System.NullReferenceException on the homepage.
What makes this super weird is that as far as Visual Studio seems concerned the content is there:
Anyone got any ideas about what I might be missing?
Odd Null Reference Error
Version: 7.10.4
Hello fellow Umbracians, I need your help.
Hoping I'm just doing something silly and I haven't had enough coffee to work out what's going wrong.
In short, I have a navigation partial where I am looking up the sites home node, and then grabbing its children:
That seems to be pretty good to me. And it works lovely on any child pages of the home page. However, it throws a System.NullReferenceException on the homepage.
What makes this super weird is that as far as Visual Studio seems concerned the content is there:
Anyone got any ideas about what I might be missing?
I'm not sure why you'd get the null reference, but you can simplify your code to just be:
Thanks Dan,
I just fell into that pattern for retrieving area pages, so, for example, we have a settings node etc. outside of the site structure.
Have tried with the Ancestor call (using ModelsBuilder so I dropped the '.Content') and still get the same error (also the same with '.Site').
is working on a reply...