Copied to clipboard

Flag this post as spam?

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


  • Dave Pearcey 46 posts 178 karma points
    Sep 13, 2017 @ 08:39
    Dave Pearcey
    0

    Null Reference Exception

    Hey.

    This is probably something simple. I've been away for a week and maybe my brain just hasn't caught up yet. I'm unable to replicate the issue locally. But application insights is reporting a null reference exception on a check for if a thumbnail has a value.

    foreach (var result in SearchResults)
                    {
                        IPublishedContent relatedArticle = Umbraco.TypedContent(result.Id);
                        if (result.Id != Umbraco.AssignedContentItem.Id && relatedArticle.HasValue("thumbnail"))
                        {
    

    Its the last line in the above code.

    Basically I'm running through some search results and i only want to display results that have a thumbnail. a lot of our legacy articles from years ago dont have a value.

    can anyone point me in the right direction?

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Sep 13, 2017 @ 08:56
    Alex Skrypnyk
    100

    Hi Dave

    Add check for null like that:

    foreach (var result in SearchResults)
    {
        IPublishedContent relatedArticle = Umbraco.TypedContent(result.Id);
        if (relatedArticle != null)
        {
            if (result.Id != Umbraco.AssignedContentItem.Id && relatedArticle.HasValue("thumbnail"))
            {
            }
        }
    }
    

    Alex

  • Dave Pearcey 46 posts 178 karma points
    Sep 13, 2017 @ 09:10
    Dave Pearcey
    0

    This seems to have worked.

    Would you be able to explain how it's possible for an article to appear in the search results if it doesnt even exist?

    My search query already negates hidden and unpublished results from being retrieved.

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Sep 13, 2017 @ 10:09
    Alex Skrypnyk
    0

    Search results from Examine? How do you do the search?

    It looks like nodes that make exception are deleted.

    Thanks,

    Alex

Please Sign in or register to post replies

Write your reply to:

Draft