Fluent API - Blog: Object reference not set to an instance of an object.
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();
[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
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!
Been a bit busy, just tried your solution.