Copied to clipboard

Flag this post as spam?

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


  • Proxicode 128 posts 324 karma points
    Oct 08, 2013 @ 22:03
    Proxicode
    0

    'umbraco.MacroEngines.DynamicNodeList' does not contain a definition for 'Random'

    Here we go again. I now have 2 Umbraco 4.11.10 sites where I can use Children.Random() and two other Umbraco 4.11.10 sites where I can not.

    I get the following error.

    'umbraco.MacroEngines.DynamicNodeList' does not contain a definition for 'Random'
    

    I am at a total loss here as I know darn well that .Random() is supported for DynamicNodes. But I now have two sites in completely different environments that both say otherwise. I have reduced my code to the one line pretty much (below) and it still fails with the same error.

    @inherits umbraco.MacroEngines.DynamicNodeContext
    @{
        dynamic image = Library.MediaById(1083).Children.Random();
    }
    

    I have tried...

    dynamic image = @Library.MediaById(1083).Children.Random();
    dynamic image = Library.MediaById(1083).Children().Random();
    dynamic image = Library.MediaById(1083).Children.Random(1);
    dynamic image = Library.MediaById(1083).ChildrenAsList.Random();
    dynamic image = Library.MediaById(1083).ChildrenAsList().Random();
    dynamic image = Model.MediaById(1083).Children.Random();
    

    I have also tried adding this reference with no change

    using umbraco.MacroEngines
    

    And various other desperate attempts. I believe at this point it might be to do with dll versions, or IIS versions, or GAC file versions, or configs or something other than syntax. Again I have 2 other sites, same version of Umbraco, where this does work.

    Incidentally, if I remove .Random(), I do get back a list of DynamicNodes that I can loop through, so at least I know that the data is good and that it is in the correct media folder.

    Here is my entire error message from the trace log.

    2013-10-08 13:42:57,772 [11] WARN  umbraco.macro - [Thread 42] Error loading MacroEngine script (file: CollageImage.cshtml, Type: ''. Exception: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'umbraco.MacroEngines.DynamicNodeList' does not contain a definition for 'Random'
       at CallSite.Target(Closure , CallSite , Object )
       at ASP._Page_macroScripts_CollageImage_cshtml.Execute() in c:\Development\CSFI\macroScripts\CollageImage.cshtml:line 5
       at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
       at System.Web.WebPages.WebPage.ExecutePageHierarchy(IEnumerable`1 executors)
       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)
       at umbraco.macro.loadMacroScript(MacroModel macro)
       at umbraco.macro.renderMacro(Hashtable pageElements, Int32 pageId)
    

    Any help or pointers would be greatly appreciated!

    Thanks -Roger

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Oct 09, 2013 @ 00:06
    Jeavon Leopold
    0

    Hi Roger,

    Are there any dll files in the bin folder of a site that doesn't work that are not present in a site that does work?

    Jeavon

  • Proxicode 128 posts 324 karma points
    Oct 09, 2013 @ 01:55
    Proxicode
    0

    @Jeavon - Thanks for the reply.  Yes, there are quite a few differences in the bin folder as this particular site was a 4.7 upgrade.  Not to mention that they are just different sites, different packages, etc.  It's worth mentioning that my other site where .Random() fails, was a clean install and not an upgrade, and I get the same error.  Also worth noting that both of the sites where Random doesn't work are using the files from the 4.11.10 download at http://our.umbraco.org/download, where as the ones that do work were created using the Microsoft Web Platform Installer.

    Is there a particular area (files) I should be looking at?  Do you know which .dll file/files would be responsible for  DynamicNodeList.Random()?

    Also I wonder if it wouldn't just be easier to find an alternative to using Random?  Any ideas?

    Thanks again!
    -Roger 

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Oct 09, 2013 @ 12:02
    Jeavon Leopold
    0

    Hi Roger,

    The key assembly is umbraco.MacroEngines.dll, if you check the assembly version for v4.11.10 it should be 1.0.4926.14936 also worth checking umbraco.macroRenderings.dll which should be 1.0.4926.14929

    See what you have in your sites.

    Jeavon

  • Proxicode 128 posts 324 karma points
    Oct 10, 2013 @ 00:12
    Proxicode
    0

    Hi Jeavon,

    Thanks for sticking with me. My file versions on the working and non-working sites match perfectly. Very perplexing.

    Anyway I ended up just using a rather lengthy workaround by using the following code.

    dynamic mediaFolder = Library.MediaById(1083);
    var theChildren = mediaFolder.Children();
    Random random = new Random();
    int randomNumber = random.Next(0, theChildren.Count());
    var image = theChildren[randomNumber];
    <img class="internalPageImage"  width="@image.umbracoWidth" height="@image.umbracoHeight" src="@image.umbracoFile" alt="@image.Name" />
    

    Thanks again for trying to help me. I'd still love to know the reason for this odd behavior between sites, but I am on a bit of time crunch on this project and had to just come up with something quickly.

    Thanks -Roger

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Oct 10, 2013 @ 10:26
    Jeavon Leopold
    0

    Hi Roger, do you have WebGrease.dll in your bin folder? If you do check which version and if less than v1.5.2, try to upgrade it to the latest version.

    Jeavon

  • pronto 61 posts 172 karma points
    Dec 09, 2013 @ 17:05
    pronto
    0

    Hi,

    Sorry to jump on this thread, I'm just wondering if anyone found a solution to this issue?

    I'm also using Umbraco 4.11.10 and I'm having exactly the same problems as Roger had above. Is there a way to specify how many random nodes to return using Roger's solution?

    pronto 

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Dec 09, 2013 @ 17:08
    Jeavon Leopold
    0

    Hi Pronto,

    Do you have WebGrease.dll in your bin folder?

    Jeavon

  • pronto 61 posts 172 karma points
    Dec 09, 2013 @ 18:09
    pronto
    0

    Hi Jeavon,

    Thanks for the reply. I don't have WebGrease.dll, no - do you think this would help? 

    pronto 

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Dec 09, 2013 @ 19:27
    Jeavon Leopold
    1

    No, I've seen it's presence cause this issue. I have also read that DotNetOAuth can cause the same issue, maybe check for that also?

  • pronto 61 posts 172 karma points
    Dec 10, 2013 @ 11:46
    pronto
    0

    Thanks for the help Jeavon - it was indeed DotNetOAuth that was the cause, weird!

    pronto

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Dec 10, 2013 @ 11:50
    Jeavon Leopold
    0

    Awesome! I know with WebGrease, the latest version didn't mess it up, maybe there is a similar solution for DotNetOAuth.

  • Proxicode 128 posts 324 karma points
    Dec 10, 2013 @ 21:35
    Proxicode
    0

    @Jeavon Leopold - Nice!  I'm glad to see this issue resurface and a solution come out at the end.  
    Thanks for your contributions!!

    -Roger

Please Sign in or register to post replies

Write your reply to:

Draft