v13: XPathValue must be an XPathNavigator or a string
a
Just upgrading a website from v10 to v13 and getting the error "XPathValue must be an XPathNavigator or a string". Whilst I understand XPath is obsolete and being removed in v14, I'd expect this to still work in v13. Here's the line of code within a partial view causing the error:
var BlogItems = Umbraco.ContentAtXPath("//blogItem").OrderByDescending(x => x.Value<DateTime>("newsDate"));
No doubt others may see this same issue with their upgrades if using a similar implementation. Any clues as to what I can do to resolve the error? Thanks! 🙂
m
Bare in mind Xpath is going away, Id be tempted to refactor this to use Linq instead 🙂
Now he reads the part where you said that 😄
(this is why I hate exam's)
a
Aye, this is unfortunately a website we inherited. I've since updated the code to become the following which has been a similar approach I've taken for a while now:
Copy code
var currentPage = Umbraco.AssignedContentItem;
var home = currentPage.AncestorOrSelf<Homepage>();
var blogItems = home.Descendants(BlogItem.ModelTypeAlias).OfType<BlogItem>().OrderByDescending(x => x.NewsDate);
Perhaps the error is there is lure you into a sense of doubt so it forces you into refactoring your code 😅
10 Views