Copied to clipboard

Flag this post as spam?

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


  • Proxicode 127 posts 323 karma points
    Sep 03, 2013 @ 21:32
    Proxicode
    0

    Razor fails using Children.Random

    Hello all,

    I am having a weird issue, hoping you all have some pointers. I am using Umbraco 4.11.10 and trying to fulfill a requirement to display 1 random quote from a collection of quotes. The really puzzling thing is that this exact code works on a different site using the same version of Umbraco. The line causing the issue is...

    var item = Model.NodeById(1150).Children.Random();
    

    If I remove .Random and output the @item variable, it is a DynamicNodeList. And I know DynamicNodeList supports Random, but the error from the error log says the following

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

    The only difference between the site where it works, and the site where it doesnt is that the site that works was setup up using the Web Platform Installer, and the one that doesn't work was setup in Visual Studio using Package Manager, so I have to assume it's a dll version or something, but so far I've had no luck.

    Any ideas?

    Thanks -Roger

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Sep 03, 2013 @ 21:47
    Dennis Aaen
    0

    Hi Roger,

    Have you tried to at an at before the Model like this:

    var item = @Model.NodeById(1150).Children.Random();

    Maybe this little change wil solve your issue with the random method.

    /Dennis

  • Proxicode 127 posts 323 karma points
    Sep 03, 2013 @ 21:51
    Proxicode
    0

    Thanks Dennis,

    Here is the entire macro with your update, but no change.

    @inherits umbraco.MacroEngines.DynamicNodeContext
    
    @{
         var item = @Model.NodeById(1150).Children.Random();
         <div>
              <blockquote>@item.quoteText<span>- @item.quoteSignature</span></blockquote>
         </div>
    }
    

    And the entire error from the log.

    2013-09-03 19:34:00,142 [11] WARN  umbraco.macro - [Thread 24] Error loading MacroEngine script (file: CFRandomQuote.cshtml, Type: ''. Exception: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'umbraco.MacroEngines.DynamicNodeList' does not contain a definition for 'Random'
       at CallSite.Target(Closure , CallSite , Object , Int32 )
       at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
       at ASP._Page_macroScripts_CFRandomQuote_cshtml.Execute() in c:\inetpub\cf\macroScripts\CFRandomQuote.cshtml:line 5
       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)
       at umbraco.macro.loadMacroScript(MacroModel macro)
       at umbraco.macro.renderMacro(Hashtable pageElements, Int32 pageId)
    

    BTW..even if I remove the div and everything inside the div, it still fails with the same error

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Sep 03, 2013 @ 22:05
    Dennis Aaen
    0

    Okay,

    DonĀ“t know if this can help you on the right way

    http://our.umbraco.org/forum/developers/razor/35398-display-random-node

    /Dennis

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Sep 03, 2013 @ 22:21
    Jeavon Leopold
    0

    Hi Roger,

    Seems odd, I just tried this sample and it seems fine....

    var a = Model.AncestorOrSelf(1).Children.Random();
    <p>@a.Name</p>
    

    Has your site always been v4.11.10 or has it been upgraded from an older version?

    Perhaps check the assembly version on umbraco.MacroEngines.dll, on my v4.11.10 site I have 1.0.4926.14936

    Jeavon

  • Proxicode 127 posts 323 karma points
    Sep 04, 2013 @ 00:51
    Proxicode
    0

    Hi Jeavon,

    Yes odd indeed. The site was created as a 4.11.10 site, no upgrades. The fact that this code works in another 4.11.10 instance makes me suspect some different dll's were used between the two types of installers, but I even went to the site where this code works, copied the Umbraco.MacroEngines.dll, the System.Web.WebPages.Razor.dll and the System.Web.Razor.dll over to the site where it is not working, but no luck there either.

    -Roger

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Sep 04, 2013 @ 08:13
    Jeavon Leopold
    0

    Hi Roger,

    I would try copying a complete clean v4.11.10 over the top (backup first) and then use source control to see if there were any differences.

    I haven't used it but I think uDiff would also do the compare for you.

    Jeavon

  • Anton Oosthuizen 206 posts 486 karma points
    Sep 09, 2013 @ 14:41
    Anton Oosthuizen
    0

    Hi I'm receiving a similar error  Umbraco v6.1.4

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

     

    It works fine on my dev environment but not in my staging environment. 

    I did a clean copy of all the DLL's but I still get the same error

  • Steve Brown 125 posts 290 karma points
    Sep 10, 2013 @ 19:29
    Steve Brown
    0

    Anton - I don't know if this would help you specifically, but there were some issues with 6.1.4 and 6.1.5 was released very quickly afterwards. Upgrading may help

  • Anton Oosthuizen 206 posts 486 karma points
    Sep 11, 2013 @ 06:59
    Anton Oosthuizen
    0

    Hi Steve

    Thanks. I'm really at a loss here.

    The original install was on version 6(All worked fine).I then upgraded to 6.1.4 when the error started happening.

    I did do an upgrade to 6.1.5 but to no avail.

    As I mentioned everything works fine on my dev box and development server but I don't have access to the staging and production server of my client(ftp only).

    Something changed with the umbraco build between 6 and 6.1.4 which breaks on my clients servers.

    At the moment is is a guessing game.

    Any Ideas welcome.

  • Greg Berlin 818 posts 634 karma points
    Sep 11, 2013 @ 07:44
    Greg Berlin
    1

    Try remove the @ from before Model.. i've had issues with that between environments before

    Here's some code I have that does very similar to what you're trying, maybe that'll help.

    @inherits umbraco.MacroEngines.DynamicNodeContext
    @using umbraco.MacroEngines
    @{
        var startNodeID = Parameter.TestimonialsFolder;
    
        if (!String.IsNullOrEmpty(startNodeID))
        {
            var startNode = Library.NodeById(startNodeID);
    
            if (startNode.TestimonialItems.Any())
            {
                var testimonialsCount = !String.IsNullOrEmpty(Parameter.TestimonialsCount) ? Convert.ToInt16(Parameter.TestimonialsCount) : 99;
                var nodes = startNode.Descendants("TestimonialItem").Random(testimonialsCount);
    
                if (testimonialsCount > 0 && nodes != null)
                {
    ........
    
  • Greg Berlin 818 posts 634 karma points
    Sep 11, 2013 @ 07:46
    Greg Berlin
    0

    Sorry I just read your original post properly, you don't have the @ symbol on there. Anyway maybe my code will help.

    Have you tried to redeploy the site to the server? Maybe under a separate IIS website?

    Not sure what else to suggest... sounds like a bit of a doozy. Good luck

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Sep 11, 2013 @ 08:23
    Jeavon Leopold
    0

    Hi Anton,

    What version of v6 did it work fine for you pre upgrade? I would like to try to reproduce, also what is the code that fails for you?

    Thanks,

    Jeavon

  • Anton Oosthuizen 206 posts 486 karma points
    Sep 11, 2013 @ 08:56
    Anton Oosthuizen
    0

    Jeavon

    I upgraded from 6.00 which worked fine.

    As I mentioned on my servers which is set up properly all is working well, but on these numbnuts' servers it ain't.

    I have no access to them so I'm shooting in the dark.

    The code:

    @inherits umbraco.MacroEngines.DynamicNodeContext

    @using Umbraco.Core.Services;

    @{

    var selection = @Model.AncestorOrSelf().Descendants("Department");
    

    }

    @*Determine if there are any nodes in the selection, then render list *@

    @if(selection.Any()){ <----YSOD

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Sep 16, 2013 @ 21:21
    Jeavon Leopold
    0

    Hi Anton,

    The only problem with that snippet is the @ before Model,

    Should be:

    @inherits umbraco.MacroEngines.DynamicNodeContext
    @using Umbraco.Core.Services;
    
    @{
    var selection = Model.AncestorOrSelf().Descendants("Department");
    }
    
    @*Determine if there are any nodes in the selection, then render list *@
    
    @if(selection.Any()){
    }
    
  • Tim 168 posts 372 karma points
    Oct 10, 2013 @ 07:09
    Tim
    1

    I keep getting 'umbraco.MacroEngines.DynamicNodeList' does not contain a definition for 'Any' whenever we install DotNetOAuth or WebGrease. As soon as the dlls are removed from the bin folder everything works fine.

    Although we have a "fix" it's not really a fix because we need the libraries. 

    Have you got either of those (or another custom library) installed?

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Oct 10, 2013 @ 10:24
    Jeavon Leopold
    0

    Tim ,absolutely, there is something bad in WebGrease that can do this, however I have found that the current version v1.5.2 doesn't have the same issue have you tried the latest version?

  • Tim 168 posts 372 karma points
    Oct 10, 2013 @ 10:37
    Tim
    0

    Jeavon, I got to the bottom of it as we're using Bundling on other sites, in my case it was that we hadn't uploaded Antlr3.Runtime.dll but I've not got to the bottom of the issue with the OAuth stuff

Please Sign in or register to post replies

Write your reply to:

Draft