Copied to clipboard

Flag this post as spam?

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


  • Michael Lawrence 128 posts 200 karma points
    Mar 25, 2011 @ 22:36
    Michael Lawrence
    0

    Using the "Take" LINQ method against a DynamicNodeList?

    I guess I'm getting a little confused with the new Dynamic types and LINQ. So I'm guessing that we don't have full access to LINQ methods against the DynamicNodeList?  For instance, the following gives me an error:

    @foreach(dynamic page in Model.Children.Take(5)) {
        @* Do something *@
    }

    And I get the error:

    Error loading Razor Script 
    'umbraco.MacroEngines.DynamicNodeList' does not contain a definition for 'Take'

    I know I could use old school ways to only pull the first 5, but is there any way to use LINQ to do this?

    Thanks!

  • Daniel Bardi 925 posts 2559 karma points
    Mar 25, 2011 @ 22:40
    Daniel Bardi
    0

    Are you referencing the LINQ assembly?

  • Michael Lawrence 128 posts 200 karma points
    Mar 25, 2011 @ 22:44
    Michael Lawrence
    0

    Yep, here's my macro code:

    <umbraco:Macro runat="server" language="razor">
    @using System.Linq
    @using System.Xml.Linq
    
    @foreach(dynamic page in Model.Children.OrderBy("publishDate descending").Take(5)) {
      <div>
    <h1>@page.Name</h1> <p><a href="@page.Url">Listen</a></p> </div> } </umbraco:Macro>
  • Michael Lawrence 128 posts 200 karma points
    Mar 25, 2011 @ 23:49
    Michael Lawrence
    0

    Actually, using "First()" doesn't work either.

    Model.Children.OrderBy("publishDate descending").First()
    Error loading Razor Script 
    'umbraco.MacroEngines.DynamicNodeList' does not contain a definition for 'First'

    Is this expected behavior, or am I doing something wrong, or is this a bug?

     

  • Michael Lawrence 128 posts 200 karma points
    Mar 26, 2011 @ 00:28
    Michael Lawrence
    0

    Ok, so for the time being I'm having to do something like this:

    <umbraco:Macro runat="server" language="razor">
    @using System.Linq
    @using System.Xml.Linq
    
    @{
        var node = new DynamicNode(Model.Id);
        var pages = node.GetChildrenAsList.Items.AsQueryable().OrderByDescending(tt  => DateTime.Parse(tt.GetProperty("publishDate").Value));
        var firstPage = pages.First();
    
        <div id="first-page">
            <h1>@firstPage.Name</h1>
            <p><a href="@firstPage.Url">Listen</a></p>
        </div>
    
        <div id="remaining-pages">
            foreach(dynamic page in pages.Skip(1).Take(5)) {
              <div>
                    <h1>@page.Name</h1>
                    <p><a href="@page.Url">Listen</a></p>
              </div>
            }
        </div>
    }
    </umbraco:Macro>

    Setting the node and pages variables seems like a bit of overkill to get what I'm trying to access. Shouldn't just doing Model.Children.OrderBy("publishDate descending").First() work?

     

  • Gareth Evans 139 posts 330 karma points c-trib
    Mar 26, 2011 @ 22:51
    Gareth Evans
    0

    Hi Michael

    Yes, the Linq extension methods should be working off DynamicNodeList
    I've just checked with my copy, and they do - what version are you running?

    If it's 4.7 final, that's very odd - I haven't changed anything to do wtih DyamicNodeList & Enumerable methods in quite a while.

     

     

  • Michael Lawrence 128 posts 200 karma points
    Mar 27, 2011 @ 00:09
    Michael Lawrence
    0

    I'm running 4.7 final. It was an upgrade from 4.6.2 so maybe I'm missing something?

  • Michael Lawrence 128 posts 200 karma points
    Mar 29, 2011 @ 23:06
    Michael Lawrence
    0

    I'm still having issues. The same thing on another site I'm building that was an upgrade as well.  Here is a simple macro that doesn't work:

    @using System.Linq
    @using System.Xml.Linq
    
    @{
      dynamic matches = Model.AncestorOrSelf(1).Descendants("Properties-Unit").Where("SquareFeet > 1000");
    
      <p>@matches.First().Name</p>
    }

    I get the following error:

    Error loading Razor Script
    'umbraco.MacroEngines.DynamicNodeList' does not contain a definition for 'First'

    What's going on here? I've made sure I followed the upgrade guide, I even used the 4.7 web.config and just changed the umbracoDbDSN and umbracoConfigurationStatus nodes, and then added the uComponents references in it. I'm not sure what else I can do. This is very strange :-/

  • Gareth Evans 139 posts 330 karma points c-trib
    Mar 29, 2011 @ 23:39
    Gareth Evans
    1

    Hi Michael

    Very odd - i've checked those methods are definitely working.

    I might need to get a copy of your umbraco site w/ database so I can run the debugger against it - obviously something is going wrong in the dynamic resolution of the extension methods. This is likely to be a file in the bin folder or similar but I won't know until I can see it in the debugger.

    Is this something you could supply to me?

    You can skype me with the username agrath - I'm on NZ time, so it's 10:40 am now

     

    Gareth

  • Michael Lawrence 128 posts 200 karma points
    Mar 30, 2011 @ 00:13
    Michael Lawrence
    0

    Sure thing. I really appreciate it! Will call you in a minute. Thanks!

  • Michael Lawrence 128 posts 200 karma points
    Mar 30, 2011 @ 02:46
    Michael Lawrence
    2

    Spoke with Gareth on Skype and he figured out it was 2 dlls causing problems. I had to remove the Microsoft.Dynamic.dll and also Microsoft.Scripting.Debugging.dll. Posting this just in case someone else runs into a similar issue in the future.

    Thanks so much Gareth! You're a badass!

  • Erik 18 posts 39 karma points
    Jul 29, 2011 @ 16:00
    Erik
    0

    I have this same problem but I don't have those DLLs. Any ideas?

    Here is my code:

    @using System.Linq
    @using System.Xml.Linq

    @inherits umbraco.MacroEngines.DynamicNodeContext

    @helper getPageTitle(dynamic node)
    {
     <text>@(!String.IsNullOrEmpty(@node.Title) ? @node.Title : @node.Name)</text>
    }

    <ul>
    @{
      var news = @Model.NodeById(@Parameter.Group).Children;
      news = news.Where("nodeTypeAlias.Equals(\"Special\")").OrderBy("publicationDate desc");
     
      if (@Parameter.IsArchive == "1") {
        news = news.Where("expirationDate < DateTime.Now");
      } else {
        news = news.Where("expirationDate > DateTime.Now && publicationDate < DateTime.Now");
      }
     
      var limit = 0;
      int.TryParse(@Parameter.Limit, out limit);
      if (limit > 0) {
        news = news.Take(limit);
      }
    }
    @foreach(var item in @news)
    {
      <li><a href="@item.Url">@getPageTitle(@item)</a>
          <span>@item.publicationDate.ToString("MMM d, yyyy")</span></li>
    }
    </ul>

  • Erik 18 posts 39 karma points
    Jul 29, 2011 @ 20:51
    Erik
    1

    I couldn't get it working dynamicaly. So I had to cast everything as its type.

    @using System.Linq
    @using System.Xml.Linq
    @using umbraco.MacroEngines

    @inherits DynamicNodeContext

    @helper getPageTitle(dynamic node)
        {
     <text>@(!String.IsNullOrEmpty(@node.Title) ? @node.Title : @node.Name)</text>
    }

    <ul>
    @{
        List<DynamicNode> news = ((DynamicNodeList)@Model.NodeById(@Parameter.Group).Children).Items;
        //news = news.Where("nodeTypeAlias.Equals(\"Special\")").OrderBy("publicationDate desc");
        news = news.Where(x => x.NodeTypeAlias.Equals("Special")).OrderByDescending(x => x.GetProperty("publicationDate").Value).ToList();
        if (@Parameter.IsArchive == "1")
        {
            //news = news.Where("expirationDate < DateTime.Now");
            news = news.Where(x => DateTime.Parse(x.GetProperty("expirationDate").Value) < DateTime.Now).ToList();
        }
        else
        {
            //news = news.Where("expirationDate > DateTime.Now && publicationDate < DateTime.Now");
            news = news.Where(x => DateTime.Parse(x.GetProperty("expirationDate").Value) > DateTime.Now
                                && DateTime.Parse(x.GetProperty("publicationDate").Value) < DateTime.Now).ToList();
        }

        int limit = 0;
        int.TryParse(@Parameter.Limit, out limit);
        if (limit > 0)
        {
            news = news.Take(limit).ToList();
        }
    }
    @foreach (DynamicNode item in @news)
    {
      <li><a href="@item.Url">@getPageTitle(@item)</a>
          <span>@String.Format(item.GetProperty("publicationDate").Value, "MMM d, yyyy")</span></li>
    }
    </ul>

  • Jeremy 5 posts 30 karma points
    Nov 18, 2011 @ 07:46
    Jeremy
    0

    NHibernate is another DLL that seems to cause this issue, which is a problem because a number of umbraco packages seem to use it.  See the work item http://umbraco.codeplex.com/workitem/30570 on the Umbraco code plex page for instructions to reproduce the issue from a base install of Umbraco 4.7.1 and vote if this reflects the problems occurring in your applicaiton.

  • Tinminator 2 posts 22 karma points
    Dec 05, 2011 @ 03:30
    Tinminator
    0

    In my case,

    Model.Children.Take

    was working, but uninstalling Umbraco Contour removed my Umbraco.Forms.Core.dll, which contains the "Take" extension method (I guess, did not bother to have a look at the source code).

    Hence, after recovering the Umbraco.Forms.Core.dll, my template just work...again.

    No

    @using System.Linq
    @using System.Xml.Linq

    required.

  • Gareth Evans 139 posts 330 karma points c-trib
    Dec 05, 2011 @ 03:33
    Gareth Evans
    1

    In short, all assemblies need all their dependencies in 4.7.1.x to be present for the extension method discovery to work.

    If you're having a problem, make sure you're running 4.7.1 and you'll see a lot more debugging in the ?umbDebugShowTrace=true output which should help to identify the offending DLL and then either remove it, or add whichever dependency is required (often when you've upgraded a site, or replaced a plugin, some DLLs are left behind but their dependencies are gone or replaced)

    Hope this generalised answer identifies the issue for someone later.

    Gareth

  • wayne nixon 12 posts 32 karma points
    Feb 02, 2014 @ 16:58
    wayne nixon
    0

    hey guys how do i check the bin folder for errors guys

    Error loading RazorScript 
    'umbraco.MacroEngines.DynamicNodeList' does not contain a definition for'any'

     

  • 10gler 5 posts 23 karma points
    Aug 05, 2014 @ 22:27
    10gler
    0

    I have the same error.

    Microsoft.Dynamic.dll and also Microsoft.Scripting.Debugging.dll - from where you removed it? You had it in project references?(I dont have these references and still have a problem).

Please Sign in or register to post replies

Write your reply to:

Draft