diff --git a/src/Umbraco.Web/umbraco.presentation/library.cs b/src/Umbraco.Web/umbraco.presentation/library.cs
index 38b8b1b95d..4ab89c5c7d 100644
--- a/src/Umbraco.Web/umbraco.presentation/library.cs
+++ b/src/Umbraco.Web/umbraco.presentation/library.cs
@@ -1393,15 +1393,25 @@ namespace umbraco
/// An XpathNodeIterator containing the current page as Xml.
public static XPathNodeIterator GetXmlNodeCurrent()
{
+ var pageId = "";
+
try
{
var nav = Umbraco.Web.UmbracoContext.Current.ContentCache.GetXPathNavigator();
- nav.MoveToId(HttpContext.Current.Items["pageID"].ToString());
+ var pageIdItem = HttpContext.Current.Items["pageID"];
+
+ if (pageIdItem == null)
+ {
+ throw new NullReferenceException("pageID not found in the current HTTP context");
+ }
+
+ pageId = pageIdItem.ToString();
+ nav.MoveToId(pageId);
return nav.Select(".");
}
catch (Exception ex)
{
- LogHelper.Error("Could not retrieve current xml node", ex);
+ LogHelper.Error(string.Concat("Could not retrieve current xml node for page Id ",pageId), ex);
}
XmlDocument xd = new XmlDocument();