0

I have been using GlassMapper for a long time, and this piece of code has always worked flawlessly; today, after playing with the children of the Home item it no longer works - even if I undo my changes.

On Internet I found no documentation for this method and its failed states - under which circumstances I should be unable to retrieve the wrapper of the website root item?

The line in question is:

var root = new SitecoreContext().GetHomeItem<MenuPage>();
Marek Musielak
  • 26,832
  • 8
  • 72
  • 80
Emanuele Ciriachi
  • 2,216
  • 2
  • 26
  • 39

3 Answers3

1

This method retrieves home item using data from your current site. You should check:

  • What is the value of Sitecore.Context.Site
  • What is the value of Sitecore.Context.Site.StartPath
  • What is the value of new SitecoreContext().Database
  • What is the value of new SitecoreContext().Database.GetItem(Sitecore.Context.Site.StartPath)
Marek Musielak
  • 26,832
  • 8
  • 72
  • 80
  • No luck. All those values are correct, and I can easily retrieve Sitecore.Context.Database.GetItem("/sitecore/content/ecosystem") which is the root of my website. But I cannot in any way retrieve the GlassMapper wrapper for this item, it always. Returns me. Null. Every single time. This never happened before and it started happening for no reason at all - and I cannot troubleshoot this because the problem, or the clue to the real problem, is nested inside Glass Mapper DLL. I'm completely stuck. – Emanuele Ciriachi Jul 17 '15 at 15:57
  • Even using the ID of the item to retrieve it, I get null. It's crazy. I tried: new SitecoreContext().GetItem() to no avail. Obviously, something else is at play here. Any clue? – Emanuele Ciriachi Jul 17 '15 at 16:05
0

This can happen if there is a publishing restriction on the home item preventing any version from being published.

So be sure to check to make sure that there isn't a publishing restriction on the home item that prevents any version from being published.

Tim Penner
  • 3,551
  • 21
  • 36
0

I was having the same problem, it turns out my site's rootPath was wrong, it was including the /Home item.

Anderson Fortaleza
  • 2,449
  • 20
  • 22