Copied to clipboard

Flag this post as spam?

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


  • Matt Geal 4 posts 74 karma points
    Mar 31, 2017 @ 15:10
    Matt Geal
    0

    Results from TypedContentAtXpath() throw exception when enumerated

    Hi guys,

    Hoping you can help me here. I'm grabbing all IPublishedContent of a particular document type using Umbraco.TypedContentAtXPath("//docType"); This works fine and seems to return an IEnumberable

        [NullReferenceException: Object reference not set to an instance of an object.]
       Umbraco.Web.PublishedCache.XmlPublishedCache.XmlPublishedContent.Get(XmlNode node, Boolean isPreviewing) +94
       System.Linq.WhereSelectEnumerableIterator`2.MoveNext() +222
    

    It's almost as if there is an entry in the Umbraco XML cache that doesn't exist in the database. I've tried clearing the app data folder. Recyling the app pool, performing a republish all but none of these have helped.

    There's definitely something wrong with the IPublishedContent collection that is coming back from Umbraco because performing .ToList() and .Count() methods on it both throw a similar error.

    Please help!

    Thanks, Matt.

  • Rune Hem Strand 147 posts 911 karma points hq c-trib
    Apr 04, 2017 @ 19:33
    Rune Hem Strand
    1

    Hi Matt

    Can't say I have experienced that :-| Would be great with a little more information.

    • Are the indexes ok?
    • Does Data integrity check pass?
    • What Umbraco version are you running?
    • Is that the full error message?
    • Finally, are there items in the recycle bin? If so could you try deleting them and see if that helps? Seem to remember that causing an issue at some point.

    All the best
    Rune

  • Matt Geal 4 posts 74 karma points
    Apr 05, 2017 @ 09:08
    Matt Geal
    0

    Thanks for taking the time to reply Rune.

    I had already tried rebuilding the indexes, it doesn't seem to make a difference.

    The data integrity check comes back as ok.

    The full error message is:

        [NullReferenceException: Object reference not set to an instance of an object.]
       Umbraco.Web.PublishedCache.XmlPublishedCache.XmlPublishedContent.Get(XmlNode node, Boolean isPreviewing) +94
       System.Linq.WhereSelectEnumerableIterator`2.MoveNext() +222
       ASP._Page_Views_MyTT_cshtml.Execute() in d:\Sites\WebSites\TT\TT-Staging\Views\MyTT.cshtml:159
       System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +252
       System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +147
       System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +106
       Umbraco.Core.Profiling.ProfilingView.Render(ViewContext viewContext, TextWriter writer) +231
       System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +374
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +89
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +833
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +833
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +833
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +81
       System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +186
       System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +38
       System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +29
       System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +65
       System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +53
       System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +36
       System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +38
       System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +44
       System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +65
       System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +38
       System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +399
       System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +137
    

    The code I'm running is:

    var ttAuthors = Umbraco.TypedContentAtXPath( "//author" );
    foreach ( IPublishedContent author in ttAuthors ) {
        if ( author != null ) {
            if ( author.Name == pm.MentorName ) {
                matchingAuthor = author;
                break;
            }
        }
    }
    

    I can happily step through the foreach statment in the debugger for several content items until it throws an error when attempting to get the next IPublishedContent item out of the collection.

    I already checked the recycle bin too! It's completely empty as far as I can tell.

    The site is running on Umbraco version 7.5.0 assembly: 1.0.6073.15895

    Is there anywhere I can check in the cms/umbraco tables to see what might be going wrong?

    Cheers, Matt.

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

    I recognise this is an old thread, but if anyone has the same issue, make sure none of your document types have a property with an alias matching the document type alias you are trying to retrieve. It's easiest to find in the XML cache in App_Data/umbraco.config

    See also my response here: https://our.umbraco.com/forum/developers/api-questions/75694-getting-a-null-collection-on-typedcontentatxpath#comment-295954

  • Rune Hem Strand 147 posts 911 karma points hq c-trib
    Sep 07, 2018 @ 06:34
    Rune Hem Strand
    0

    Hi Chris,

    that makes a whole bunch of sense and is most likely the reason for the error described above.

    Thanks for taking the time to reply to an old thread - Really helpful!

    h5yr 🙌
    /rune

Please Sign in or register to post replies

Write your reply to:

Draft