Copied to clipboard

Flag this post as spam?

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

  • kleptbit 42 posts 98 karma points
    May 18, 2015 @ 16:54

    I moved the search and now it fails Umbraco 6.0.5 and uBlogsy Razor 3



    I have a requirement to redesign an existing blog and have to move the search to the home page. I moved uBlogsyWidgetSearch to run from uBlogsyGlobalNavigation, and I get a YSOD with a null reference exception on the landing.url.

    Does anyone have any idea how I can make search work again please? I know the way landing is cached was changed in a later version but I don't have the luxury of upgrading.

    Object reference not set to an instance of an object.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

    Source Error: 

    Line 20: 
    Line 21:            $(window.location.href = "@landing.Url()" + '?search=' + $("#uBlogsyTxtSearch").val());
    Line 22:             return false;
  • kleptbit 42 posts 98 karma points
    May 21, 2015 @ 13:03

    Ok so I fixed it myself to search from the home page or siblings, not on the blog.

    1) I made a new SearchDataService.cs class and put it in the AppCode folder.

    2) I copied the existing DataService.cs file and altered the following:

        interface IuBlogsyService
            string GetValueFromLanding(IPublishedContent node, string propertyAlias);

            string GetValueFromAncestor(IPublishedContent node, string ancestorAlias, string propertyAlias);
          //****changed from GetLanding to SearchGetLanding***
           IPublishedContent SearchGetLanding(IPublishedContent node);

            IPublishedContent GetSiteRoot(IPublishedContent node, string rootNodeTypeAlias);

    3) I altered the GetLanding to SearchGetLanding and made it find the uBlogsyLanding whether it was starting from uBlogsySiteRoot or from a sibling node:

            /// <summary>
            /// Gets landing node, caches result.
            /// </summary>
            /// <param name="node">A node which is a descendant, ascendant or sibling of landing.</param>
            /// <returns></returns>
            public IPublishedContent SearchGetLanding(IPublishedContent node)
                string cacheKey = "GetLanding_uBlogsyLanding";
                IPublishedContent landing;
                var cached = CacheHelper.GetFromRequestCache(cacheKey) as IPublishedContent;
                if (cached != null)
                    return cached;

                if (node.DocumentTypeAlias.ToString() == "uBlogsySiteRoot")
                    landing = node.DescendantsOrSelf("uBlogsyLanding").First();
                    return landing;
                if (node.DocumentTypeAlias.ToString() == "uBlogsyPage")
                    bool nodeSibling = node.Sibling("uBlogsyLanding").IsFirst();
                    if (nodeSibling == true)
                        landing = node.Sibling("uBlogsyLanding").DescendantsOrSelf(1).First();
                    return landing;

                    landing = node.AncestorOrSelf("uBlogsyLanding");

                    // cache the result
                    CacheHelper.AddToRequestCache(cacheKey, landing);

                    return landing;


    I have no doubt it'll break if I add any other sections with different DocumentTypeAlias relationships but it's working for now....

Please Sign in or register to post replies

Write your reply to: