Upgraded Umbraco to 4.9 -- get call is ambiguous: GetDescendantNodes()
Greetings all!
We got an odd issue. After we upgraded to 4.9 (from 4.7.1.1), we started getting an ambiguous error with code we had been using before the upgrade. Methods that we were using such as GetDescendantNodes() are now giving us a conflict error, like it doesn't know which method to use. We have upgraded our uComponents library to version 5. Other methods giving us ambiguous using errors are HasProperty, GetPropertyByDateTime, etc...
Since we can't call GetDescendantNodes() directly (like umbraco.NodeFactory.Node.GetDescendants()...) because we're using it directly after a uQuery.GetRootNode(), we're at a loss on what to do next. I'm pretty sure it's a upgrade issue... or a using conflict... :(
Does anyone have any ideas? Sorry for the trouble -- and thank you so much in advance!
Here is the error:
Error occured d:\WebSites\dmns.org\macroScripts\634867805575535460_DWTSideBarArchives.cshtml(13): error CS0121: The call is ambiguous between the following methods or properties: 'uComponents.Core.uQueryExtensions.NodeExtensions.GetDescendantNodes(umbraco.NodeFactory.Node)' and 'umbraco.NodeExtensions.GetDescendantNodes(umbraco.NodeFactory.Node)'
Here's the original code:
@using umbraco.MacroEngines @using uComponents.Core.uQueryExtensions @inherits umbraco.MacroEngines.DynamicNode @inherits umbraco.MacroEngines.DynamicNodeContext @{ // for LIVE site, switch "dwtAlternatePostDate" with "dwtBlogPostDate" var baseNode = @Model.AncestorOrSelf("DWTBlogLanding"); var blogPostPropertyName = "dwtBlogPostDate"; var archiveNodes = uQuery.GetRootNode().GetDescendantNodes().Where(x => x.NodeTypeAlias == "ScienceResearchUpdatesPost" && x.HasProperty(blogPostPropertyName)).OrderByDescending(x => x.GetPropertyAsDateTime(blogPostPropertyName)); <h3>@Dictionary.DWTArchive</h3> <ul> @for (int i = 0; i < 12; i++) { var date = DateTime.Now.AddMonths(-i); var numOfBlogsThisMonth = NumberOfBlogsInMonth(archiveNodes, date, blogPostPropertyName ); if (numOfBlogsThisMonth == 0) { <li>@DateTime.Now.AddMonths(-i).ToString("MMMM, yyyy") (0)</li>; } else { var dateString = date.ToString("MM-dd-yyyy"); <li><a href="@baseNode.Url?altArchive=@dateString">@DateTime.Now.AddMonths(-i).ToString("MMMM, yyyy") (@numOfBlogsThisMonth)</a></li>; } } </ul> } @functions{ public static int NumberOfBlogsInMonth(IEnumerable<umbraco.NodeFactory.Node> nodes, DateTime archiveDate, string PropertyName) { var nodeList = new List<umbraco.NodeFactory.Node>(); foreach (var node in nodes) { var nodeDate = node.GetPropertyAsDateTime(PropertyName); if (nodeDate.Month == archiveDate.Month && nodeDate.Year == archiveDate.Year) { nodeList.Add(node); } } return nodeList.Count(); } public static int NumberOfMonthsArchive(DynamicNodeList nodes) { var monthsDifference = (DateTime.Now.Year * 12 + DateTime.Now.Month) - (nodes.Items.LastOrDefault().CreateDate.Year * 12 + nodes.Items.LastOrDefault().CreateDate.Month); return monthsDifference; } }
That's because parts of uComponents (like uQuery) have been included in Umbraco. You may be able to just remove your using statement for uComponents.Core.uQueryExtensions and then call it good.
Thanks for the input Douglas! We tried that before but it didn't quite work right either. So we ended up fixing our issue by cleaning up our Using to just this:
@using umbraco.MacroEngines
@inherits umbraco.MacroEngines.DynamicNode
@inherits umbraco.MacroEngines.DynamicNodeContext
Declaring which specific node we're using to this: "umbraco.NodeFactory.Node"
And then converting all of conflicting methods we were using to a format like this:
GetPropertyAsDateTime() to GetProperty<DateTime>()
GetPropertyAsInt() to GetProperty<int>()
This cleared things up for us. Thanks for your help!
Upgraded Umbraco to 4.9 -- get call is ambiguous: GetDescendantNodes()
Greetings all!
We got an odd issue. After we upgraded to 4.9 (from 4.7.1.1), we started getting an ambiguous error with code we had been using before the upgrade. Methods that we were using such as GetDescendantNodes() are now giving us a conflict error, like it doesn't know which method to use. We have upgraded our uComponents library to version 5. Other methods giving us ambiguous using errors are HasProperty, GetPropertyByDateTime, etc...
Since we can't call GetDescendantNodes() directly (like umbraco.NodeFactory.Node.GetDescendants()...) because we're using it directly after a uQuery.GetRootNode(), we're at a loss on what to do next. I'm pretty sure it's a upgrade issue... or a using conflict... :(
Does anyone have any ideas? Sorry for the trouble -- and thank you so much in advance!
Here is the error:
Here's the original code:
That's because parts of uComponents (like uQuery) have been included in Umbraco. You may be able to just remove your using statement for uComponents.Core.uQueryExtensions and then call it good.
Thanks for the input Douglas! We tried that before but it didn't quite work right either. So we ended up fixing our issue by cleaning up our Using to just this:
Declaring which specific node we're using to this: "umbraco.NodeFactory.Node"
And then converting all of conflicting methods we were using to a format like this:
This cleared things up for us. Thanks for your help!
Greg
is working on a reply...