Does not contain a definition for Children... MYSTERY!
I am making a macro designed to list Related Posts. The macro compiles, however failes at run time. It throws this error:
umbracoMacro
Error Loading Razor Script (file: Blogpost Related Pages) 'umbraco.MacroEngines.DynamicNodeList' does not contain a definition for 'Children' at CallSite.Target(Closure , CallSite , Object ) at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0) at ASP._Page_macroScripts_RelatedPosts_cshtml.Execute() in d:\home\mblearning.orcare.com\htdocs\macroScripts\RelatedPosts.cshtml:line 8 at System.Web.WebPages.WebPageBase.ExecutePageHierarchy() at System.Web.WebPages.WebPage.ExecutePageHierarchy() at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) at umbraco.MacroEngines.RazorMacroEngine.ExecuteRazor(MacroModel macro, INode currentPage) at umbraco.MacroEngines.RazorMacroEngine.Execute(MacroModel macro, INode currentPage)
1.021373536
1.007194
umbracoMacro
Loading IMacroEngine script [done]
1.021497888
0.000124
umbracoMacro
Error loading MacroEngine script (file: RelatedPosts.cshtml, Type: '' 'umbraco.MacroEngines.DynamicNodeList' does not contain a definition for 'Children' at umbraco.macro.renderMacro(Hashtable pageElements, Int32 pageId)
Surely this must be a dll problem? This is the macro I am using
<h3 class="commentsheader">Related posts</h3> <ul class="relatedPostsList"> @{ var currentTags = umbraco.cms.businesslogic.Tags.Tag.GetTags(@Model.Id); int i = 0; bool found = false; foreach (var blogItem in Model.AncestorsOrSelf("Blog").Children.Where("Visible && i < 5 && NodeTypeAlias == \"BlogPost\"").OrderBy("createDate desc")) { found = false; foreach (var relatedTags in umbraco.cms.businesslogic.Tags.Tag.GetTags(@blogItem.Id)) { if(currentTags.Contains(relatedTags) && found == false) { found = true; <li> <a href="@blogItem.Url">@blogItem.Name</a> </li> } i++; } } } </ul>
The problem comes from the fact that yout statement Model.AncestorsOrSelf("Blog") returns a DynamicNode List, and not a single DynamicNode. And the DynamicNodeList object does not have the "Children" property, only the DynamicNode does.
In your case you probably have only one "Blog" node, so what you need to do is extract the "first node" from the list, so something like
Does not contain a definition for Children... MYSTERY!
I am making a macro designed to list Related Posts. The macro compiles, however failes at run time. It throws this error:
at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)
at ASP._Page_macroScripts_RelatedPosts_cshtml.Execute() in d:\home\mblearning.orcare.com\htdocs\macroScripts\RelatedPosts.cshtml:line 8
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
at System.Web.WebPages.WebPage.ExecutePageHierarchy()
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
at umbraco.MacroEngines.RazorMacroEngine.ExecuteRazor(MacroModel macro, INode currentPage)
at umbraco.MacroEngines.RazorMacroEngine.Execute(MacroModel macro, INode currentPage)
'umbraco.MacroEngines.DynamicNodeList' does not contain a definition for 'Children'
at umbraco.macro.renderMacro(Hashtable pageElements, Int32 pageId)
Surely this must be a dll problem? This is the macro I am using
<h3 class="commentsheader">Related posts</h3>
<ul class="relatedPostsList">
@{
var currentTags = umbraco.cms.businesslogic.Tags.Tag.GetTags(@Model.Id);
int i = 0;
bool found = false;
foreach (var blogItem in Model.AncestorsOrSelf("Blog").Children.Where("Visible && i < 5 && NodeTypeAlias == \"BlogPost\"").OrderBy("createDate desc"))
{
found = false;
foreach (var relatedTags in umbraco.cms.businesslogic.Tags.Tag.GetTags(@blogItem.Id))
{
if(currentTags.Contains(relatedTags) && found == false)
{
found = true;
<li>
<a href="@blogItem.Url">@blogItem.Name</a>
</li>
}
i++;
}
}
}
</ul>
Hi jacob,
The problem comes from the fact that yout statement Model.AncestorsOrSelf("Blog") returns a DynamicNode List, and not a single DynamicNode. And the DynamicNodeList object does not have the "Children" property, only the DynamicNode does.
In your case you probably have only one "Blog" node, so what you need to do is extract the "first node" from the list, so something like
Model.AncestorsOrSelf("Blog").First().Children...
Hope this helps.
Cheers,
Michael.
is working on a reply...