Copied to clipboard

Flag this post as spam?

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


  • Grant Thomas 291 posts 324 karma points
    Nov 28, 2012 @ 13:36
    Grant Thomas
    0

    NullReferenceException at uBlogsy.BusinessLogic.PostService.GetContentForPage

    I've installed the package successfully and unlike previously tried packages this looks like it could fit the bill perfects, albeit with some stuff removed that we don't need (as one might expect). So I removed a number of document types: I kept the base pages, landing, post, comment, comment container, email template, email template container and RSS (all date folders and 'extra' ones have been removed).

    I created a new template for the landing page document type and basically done a copypasta from uBlogsyBaseSite and inserted the markup from uBlogsyLanding which lists the children (blog psots) under that node.

    Now, when I use the uBlogsyListPosts macro I get a NullReferenceException on the following line:

    IEnumerable<DynamicNode> posts = PostService.Instance.GetPosts(Model.Id, tag, category, author, searchTerm, commenter, page - 1, count);
    

    Though the exception actually occurs in a method call invoked *from* that method (uBlogsy.BusinessLogic.PostService.GetContentForPage - see below for stack trace). Noticing many of the parameter arguments were null strings, I tried making them empty strings instead (if no value was present):

    var tag = Request.QueryString["tag"] ?? "";
    var category = Request.QueryString["category"] ?? "";
    var author = Request.QueryString["author"] ?? "";
    var searchTerm = Request.QueryString["search"] ?? "";
    var commenter = Request.QueryString["commenter"] ?? "";

    I didn't think this would be the case as they're not necessary anyway, and I was right. The problem persists.

    So, the stack trace to show where this is actually happening is this:

    Error Loading Razor Script (file: uBlogsy - List Posts) Object reference not set to an instance of an object.    at uBlogsy.BusinessLogic.PostService.<GetPosts>b__1(DynamicNode x)
      at System.Linq.Enumerable.<>c__DisplayClassf`1.<CombinePredicates>b__e(TSource x)
      at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
      at System.Linq.Enumerable.<DistinctIterator>d__81`1.MoveNext()
      at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
      at System.Linq.OrderedEnumerable`1.<GetEnumerator>d__0.MoveNext()
      at System.Linq.Enumerable.Count[TSource](IEnumerable`1 source)
      at uBlogsy.BusinessLogic.PostService.GetContentForPage(IEnumerable`1 nodes, Int32 pageNo, Int32 itemsPerPage)
      at uBlogsy.BusinessLogic.PostService.GetPosts(Int32 nodeId, String tag, String category, String author, String searchTerm, String commenter, Int32 pageNo, Int32 itemsPerPage)
      at ASP._Page_macroScripts_uBlogsy_uBlogsyListPosts_cshtml.Execute()

    All I can say is that Model.Id, the only thing that should matter, is something, not null.

  • Anthony Dang 1404 posts 2558 karma points MVP 3x c-trib
    Nov 28, 2012 @ 15:02
    Anthony Dang
    0

    Was this working before you removed stuff?

    Can you paste a snap of your content tree?

     

    Also, try page = -2 in the query to see if anything is returned.

    This should return all the posts. If there are no posts returned, then I would try the above. 

    Since removing a bunch of stuff from the package possibly broke something, I would start from the beggining and test each time you remove something so that you can figure out what is causing the issue.

     

  • Grant Thomas 291 posts 324 karma points
    Nov 28, 2012 @ 15:20
    Grant Thomas
    0

    Anthony, thanks for the response.

    page - 2 doesn't make a difference unfortunately. I've just downloaded the source so will take a look, might just be quicker to recompile if the issue is obvious and avoidable.

  • Grant Thomas 291 posts 324 karma points
    Nov 28, 2012 @ 17:14
    Grant Thomas
    0

    Anthony, the problem was/is with 'node.GetProperty' using 'umbracoNaviHide' in a Linq query without checking whether the property exists or not first, expecting to be able to do '.Value', which, naturally, explodes. So, the solution is to re-add umbracoNaviHide to the base document type (which I can guarantee won't be getting done in this case), or recompile without the check.

    For reference, the problem line is this:

    // get entire list of posts
    IEnumerable<DynamicNode> postList = GetPosts(nodeId).Where(x => x.GetProperty("umbracoNaviHide").Value != "1");
  • Anthony Dang 1404 posts 2558 karma points MVP 3x c-trib
    Nov 30, 2012 @ 11:08
    Anthony Dang
    0

    Well this is currenlty a core functionality and also umbraco convension.

    The property needs to be there. In future versions I may have more granular toggling, but ther properties still need to exist.

    In the meantime, I suggest downloading the source and modifying it, or alternatively, use something like uHidesy if you don't want the editor to see the property.

     

     

Please Sign in or register to post replies

Write your reply to:

Draft