Error: Object reference not set to an instance of an object.
Hello everyone, I am a newbie to umbraco v8. I am trying to create an article list page and In that i am trying to display finite number of articles when the home page loads but I am not really understanding what does this error mean?
Error: Object reference not set to an instance of an object.
here is the code:
public ArticleResultSet GetLatestArticles(IPublishedContent currentContentItem, HttpRequestBase request)
{
var siteRoot = currentContentItem.Root();
var articleList = GetArticleListPage(siteRoot);
var articles = articleList.Descendants().Where(x => x.ContentType.Alias == "article" && x.IsVisible()).OrderByDescending(y => y.Value<DateTime>("articleDate"));
var isArticleListPage = articleList.Id == currentContentItem.Id;
var fallbackPageSize = isArticleListPage ? 10 : 3;
var pageNumber = QueryStringHelper.GetIntFromQueryString(request, "page", 1);
var pageSize = QueryStringHelper.GetIntFromQueryString(request, "size", fallbackPageSize);
var pageOfArticles = articles.Skip((pageNumber - 1) * pageSize).Take(pageSize);
var totalItemCount = articles.Count();
var pageCount = totalItemCount > 0 ? Math.Ceiling((double)totalItemCount / pageSize) : 1;
var resultSet = new ArticleResultSet() {
PageCount = pageCount,
PageNumber = pageNumber,
PageSize = pageSize,
Results = pageOfArticles,
IsArticleListPage = isArticleListPage,
Url = articleList.Url
};
return resultSet;
}
Error: Object reference not set to an instance of an object.
Hello everyone, I am a newbie to umbraco v8. I am trying to create an article list page and In that i am trying to display finite number of articles when the home page loads but I am not really understanding what does this error mean?
Error: Object reference not set to an instance of an object.
here is the code:
can someone please help me?
Hi
When you are trying to check the ids of the current content item and the articleList item you are getting the null error.
It looks like articleList is null. Can you run the site in debug mode and step through those lines to see if a value is set to articleList?
Kind regards
Paul
Hi paul,
Thanks for the response, I am have been following your umbraco v8 series and its been really fun so far.
I have managed to solve the error, apprently I need store the result in a variable in method GetArticleListPage(), then return it.
thanks again for your help!
is working on a reply...