Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
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)
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 as dynamic;
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.
Write your reply to:
Image will be uploaded when post is submitted