Copied to clipboard

Flag this post as spam?

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


  • Arjan 21 posts 91 karma points
    Mar 08, 2016 @ 14:44
    Arjan
    0

    getting a null collection on TypedContentAtXPath

    Hello, I try to get all pages of a certain doctype out of the repository and use the function TypedContentAtXPath for that, as it is just one call.

    On a certain doctype it returns a result which is not null, but the results enumeration fails with a null pointer.

       var pagesOfDoctype = Umbraco.ContentQuery.TypedContentAtXPath(string.Format("//{0}", doctypeNode.Alias));
    
    foreach (var page in pagesOfDoctype)
    {
       ...
    }
    

    The debugger shows the variable pagesOfDoctype as non-null linq variable, but the results view shows "Object reference not set to an instance of an object".

    This looks like a umbraco bug, 2 questions:

    1 How do I test for this case? Testing the results collection using

    pagesOfDoctype.getEnumerator() == null 
    

    does not work

    2 is TypedContentAtXPath considered legacy? ifyes the bug will not be fixed, what is the alternative?

  • Chris Roberts 74 posts 106 karma points c-trib
    Sep 13, 2016 @ 10:18
    Chris Roberts
    0

    Hi,

    I think I might be hitting the same problem... did you ever resolve this?

    I'm working on a site where most calls to TypedContentAtXPath are working fine, but one in particular is throwing an exception "Object reference not set to an instance of an object" when I attempt to retrieve the results.

    Stack Trace:

    at Umbraco.Web.PublishedCache.XmlPublishedCache.XmlPublishedContent.Get(XmlNode node, Boolean isPreviewing)
       at Umbraco.Web.PublishedCache.XmlPublishedCache.PublishedContentCache.<>c__DisplayClass1.<ConvertToDocuments>b__0(XmlNode xmlNode)
       at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
       at System.Linq.SystemCore_EnumerableDebugView`1.get_Items()
    

    I'm running Umbraco 7.5.3. I've rebuilt my indexes, republished the entire site, deleted umbraco.config to try and rule out any possible problems in that regard, but with no luck. It does seem to be isolated to this particular document type!?

    Any help from anyone would be appreciated!

  • Arjan 21 posts 91 karma points
    Sep 13, 2016 @ 10:40
    Arjan
    0

    nope, I just catch the exception and move on ;) good luck!

  • Chris Kim 48 posts 254 karma points c-trib
    Sep 07, 2018 @ 00:44
    Chris Kim
    0

    I just had the same issue on an Umbraco 7.6.4 instance.

    I eventually found that one of my document types had a PROPERTY with the same alias as the document type alias I was trying to retrieve with TypedContentSingleAtXPath.

    Renaming that property alias fixed the issue.

    If you look at the XML in umbraco.config it actually makes perfect sense that having the same document type alias and property alias can cause these kinds of issues.

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Sep 07, 2018 @ 07:48
    Dave Woestenborghs
    0

    Hi Arjan,

    You can also do this in your xpath query :

    //doctypeAlias[@isDoc]
    

    All documents are have the isDoc attribute. So in case you have a property alias that is the same this will only get the documents

    Dave

  • Chris Kim 48 posts 254 karma points c-trib
    Sep 10, 2018 @ 23:26
    Chris Kim
    0

    Thanks Dave, that's good to know.

  • Jamie Attwood 207 posts 501 karma points c-trib
    Jun 04, 2019 @ 13:38
    Jamie Attwood
    0

    Thank-you Dave, this cost me a few hours! Changing my query to:

    Umbraco.TypedContentAtXPath("//mydocumenttypealias[@isDoc]");
    

    Works like a charm!

Please Sign in or register to post replies

Write your reply to:

Draft