Hi, I'm attempting to write a Razor script by having a issue when a Node has been deleted by the reference still exists within a node property.
Using Library.NodeById(<Id>) I get an exception
System.NullReferenceException: Object reference not set to an instance of an object.
at umbraco.MacroEngines.ExamineBackedMedia.GetUmbracoMedia(Int32 id)
at umbraco.MacroEngines.DynamicBackingItem..ctor(Int32 Id)
at umbraco.MacroEngines.DynamicNode..ctor(Int32 NodeId)
at umbraco.MacroEngines.Library.RazorLibraryCore.NodeById(Int32 Id)
at ASP._Page_macroScripts_ProductCategorySidebar_cshtml.Execute()
Is there a method that exists to check if the node exists instead of enclosing within a try catch to avoid the exception stopping the render?
For a temporay fix I have added the code below as a function. I start from -1 as the object I require exist within a Global section in the node tree where I hold Banners, Promotions etc for better site structuring.
Razor exception getting NodeById
Hi, I'm attempting to write a Razor script by having a issue when a Node has been deleted by the reference still exists within a node property.
Using Library.NodeById(<Id>) I get an exception
Is there a method that exists to check if the node exists instead of enclosing within a try catch to avoid the exception stopping the render?
For a temporay fix I have added the code below as a function. I start from -1 as the object I require exist within a Global section in the node tree where I hold Banners, Promotions etc for better site structuring.
public dynamic GetNodeById (int Id) { DynamicNodeList colNodes = ((DynamicNode)Library.NodeById(-1)).Descendants(n => n.Id == Id);if (colNodes != null && colNodes.Items.Count != 0) { return colNodes.Items[0] as dynamic; }
return null; }
Thanks Andy
I should I read the
Didn't realize it uses examine and just updated it, didn't work so was debugging for got to put the InternalIndexSet back. Working now.
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.