Fluent API - Blog: Object reference not set to an instance o

Posted by Community Admin on 04-Aug-2018 14:54

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

All Replies

Posted by Community Admin on 14-Aug-2012 00:00

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

Posted by Community Admin on 15-Aug-2012 00:00

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!

Posted by Community Admin on 21-Aug-2012 00:00

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

This thread is closed