More in this section

Forums / Developing with Sitefinity / Fluent API - Blog: Object reference not set to an instance of an object.

Fluent API - Blog: Object reference not set to an instance of an object.

3 posts, 1 answered
  1. Shane
    Shane avatar
    9 posts
    Registered:
    17 Jul 2012
    14 Aug 2012
    Link to this post
    Good Morning All,

    I came across an issue with the fluent API. I developed a custom widget for display blog post titles. It worked well and was quick to make. About a week later into dev I noticed it had stopped working. Turns out it's been spouting an error saying that "Object reference not set to an instance of an object."

    When I use this line

    IQueryable<BlogPost> Results = App.WorkWith().Blog().BlogPosts().Publihed().Where(n => n.Status == ContentLifecycleStatus.Live).OrderBy(posts => posts.PublicationDate).Get(); 

    I'm confused as to why this is happening, I have made no changes to that widget and I'm not entirely sure when it started happening and what other changes I have made

    Here is the stack trace
    [NullReferenceException: Object reference not set to an instance of an object.]
       Telerik.Sitefinity.Fluent.ContentFluentApi.BlogsSingularFacade`1.BlogPosts() +81
       SitefinityWebApp.Custom.Widgets.BlogPostsWidget.Page_Load(Object sender, EventArgs e) in C:\ omitted\Custom\Widgets\BlogPostsWidget.ascx.cs:85
       System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +24
       System.Web.UI.Control.LoadRecursive() +94
       System.Web.UI.Control.LoadRecursive() +189
       System.Web.UI.Control.LoadRecursive() +189
       System.Web.UI.Control.LoadRecursive() +189
       System.Web.UI.Control.LoadRecursive() +189
       System.Web.UI.Control.LoadRecursive() +189
       System.Web.UI.Control.LoadRecursive() +189
       System.Web.UI.Control.LoadRecursive() +189
       System.Web.UI.Control.LoadRecursive() +189
       System.Web.UI.Control.LoadRecursive() +189
       System.Web.UI.Control.LoadRecursive() +189
       System.Web.UI.Control.LoadRecursive() +189
       System.Web.UI.Control.LoadRecursive() +189
       System.Web.UI.Control.LoadRecursive() +189
       System.Web.UI.Control.LoadRecursive() +189
       System.Web.UI.Control.LoadRecursive() +189
       System.Web.UI.Control.LoadRecursive() +189
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2759

    Has anyone experienced anything similar? It would appear it's being caused by BlogPosts() to not be instantiated but I'm confused as to why
  2. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    Registered:
    18 Jul 2012
    15 Aug 2012
    Link to this post
    I'm not sure if this is the cause of the error, but the Blog() method has an overload that takes a Guid for the specific blog from which you want posts.

    If you truly want all of the posts in the system, try skiping Blogs() and using App.WorkWith().BlogPosts() directly and see if that lets you get them all.

    Hope this is helpful!
    Answered
  3. Shane
    Shane avatar
    9 posts
    Registered:
    17 Jul 2012
    21 Aug 2012
    Link to this post
    Been a bit busy, just tried your solution.

    Wow I'm surprised that worked but it got the job done. It's now returning blog posts again. Thank you very much sir
3 posts, 1 answered