Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Brian Powell 43 posts 198 karma points c-trib
    Nov 20, 2015 @ 05:32
    Brian Powell
    0

    ValueFactory InvalidOperationException when using macro recursively include child pages

    tl;dr Version: I'm getting an InvalidOperationException exception "ValueFactory attempted to access the Value property of this instance." when trying to use a macro to include child pages and one of those children uses the same macro to include its children.


    I'm using Umbraco 7.2.8 with ASP.NET Masterpages, but I've transitioned all of my macros to use Partial View Macros.

    I'm using Umbraco to host a website for a college course. I want to divide our course syllabus into a series of nested pages so I can link to things on a very granular level. Here's my general page structure for this:

    - Syllabus (Level 1)
    |- Course Materials (Level 2)
     |- Course Textbook (Level 3)
     |- Course Software
    |- Course Policies
     |- Attendance Policy
     |- Academic Integrity Policy
    

    If the user goes to the Course Textbook page, they should just see that section. If they go to the Course Materials page, they should see both child pages of that node. If they go to the top level Syllabus page, they should see everything included.

    At each of the parent levels, I'm using a macro that runs a foreach loop to display the bodyText field of the CurrentPage.Children nodes. This works OK from Level 2, but at Level 1 where its children call the same macro, I get a InvalidOperationException exception "ValueFactory attempted to access the Value property of this instance."

    I've tried all sorts of different ways of accessing the bodyText property with the child contents (dynamic type, strongly typed, helper class) and they all end up with a similar stack trace:

    2015-11-19 21:19:52,000 [11] WARN  umbraco.macro - [P3972/T1/D2] Error loading partial view macro (View: ~/Views/MacroPartials/CS101IncludeChildPages.cshtml). Exception: System.InvalidOperationException: ValueFactory attempted to access the Value property of this instance.
       at System.Lazy`1.CreateValue()
       at System.Lazy`1.LazyInitValue()
       at System.Lazy`1.get_Value()
       at Umbraco.Web.PublishedCache.XmlPublishedCache.XmlPublishedProperty.get_Value()
       at Umbraco.Web.Models.DynamicPublishedContent.TryGetUserProperty(GetMemberBinder binder)
       at Umbraco.Web.Models.DynamicPublishedContent.<>c__DisplayClass9.<TryGetMember>b__6(Func`2 m)
       at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
       at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
       at Umbraco.Web.Models.DynamicPublishedContent.TryGetMember(GetMemberBinder binder, Object& result)
       at CallSite.Target(Closure , CallSite , Object )
       at ASP._Page_Views_MacroPartials_CS101IncludeChildPages_cshtml.Execute() in c:\Web-Dir\umbraco\Views\MacroPartials\CS101IncludeChildPages.cshtml:line 15
       at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
       at System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
       at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
       at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance)
       at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer)
       at Umbraco.Core.Profiling.ProfilingView.Render(ViewContext viewContext, TextWriter writer)
       at Umbraco.Web.Mvc.ControllerExtensions.RenderViewResultAsString(ControllerBase controller, ViewResultBase viewResult)
       at Umbraco.Web.Macros.PartialViewMacroEngine.Execute(MacroModel macro, IPublishedContent content)
       at Umbraco.Web.Macros.PartialViewMacroEngine.Execute(MacroModel macro, INode node)
       at umbraco.macro.LoadPartialViewMacro(MacroModel macro)
       at umbraco.macro.renderMacro(Hashtable pageElements, Int32 pageId)
    

    Is this a bug? The only solution I've found is to call RenderTemplate with a template that just includes bodyText, but this seems like a kludgy solution. Anyone have any better ideas?

Please Sign in or register to post replies

Write your reply to:

Draft