Error after installing version 2.6

May 14, 2012 at 2:53 PM

Hello,

I get this error after installing. Any help? It looks a code error or config error

 

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]
   BlogEngine.Core.Category.CompleteTitle() in J:\Projects\BlogEngine_2_6_0_5\Source\BlogEngine\BlogEngine.Core\Category.cs:363
   BlogEngine.Core.Category.CompareTo(Category other) in J:\Projects\BlogEngine_2_6_0_5\Source\BlogEngine\BlogEngine.Core\Category.cs:399
   System.Collections.Generic.GenericArraySortHelper`1.QuickSort(T[] keys, Int32 left, Int32 right) +264
   System.Collections.Generic.GenericArraySortHelper`1.Sort(T[] keys, Int32 index, Int32 length, IComparer`1 comparer) +192

[InvalidOperationException: Failed to compare two elements in the array.]
   System.Collections.Generic.GenericArraySortHelper`1.Sort(T[] keys, Int32 index, Int32 length, IComparer`1 comparer) +12489516
   System.Collections.Generic.List`1.Sort(Int32 index, Int32 count, IComparer`1 comparer) +118
   BlogEngine.Core.Category.get_AllBlogCategories() in J:\Projects\BlogEngine_2_6_0_5\Source\BlogEngine\BlogEngine.Core\Category.cs:160
   BlogEngine.Core.Category.GetCategory(Guid id, Boolean acrossAllBlogInstances) in J:\Projects\BlogEngine_2_6_0_5\Source\BlogEngine\BlogEngine.Core\Category.cs:352
   BlogEngine.Core.Web.Controls.PostViewBase.CategoryLinks(String separator) in J:\Projects\BlogEngine_2_6_0_5\Source\BlogEngine\BlogEngine.Core\Web\Controls\PostViewBase.cs:279
   ASP.themes_standard_postview_ascx.__Render__control1(HtmlTextWriter __w, Control parameterContainer) +912
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +131
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +246
   System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) +48
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +246
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +246
   ASP.themes_standard_site_master.__Render__control5(HtmlTextWriter __w, Control parameterContainer) +1392
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +131
   System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter writer) +11412639
   System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) +48
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +246
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +246
   System.Web.UI.Page.Render(HtmlTextWriter writer) +40
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5290

 

Coordinator
May 14, 2012 at 5:14 PM

Could it be content related? For example, if you have post with category that does not exist in the category file or table, depending on provider.

Aug 19, 2012 at 10:52 PM

I also had this error. I learned that it finds categories which are empty. Do not know what the problem is but I updated the code to work only with categories of the current blog.in category.cs.

 I added an overloaded method for GetCategory and changed the current one.

        public static Category GetCategory(Guid id)
        {
            return GetCategory(id, false);
        }

        public static Category GetCategory(Guid id, bool acrossAllBlogInstances)
        {
            return (acrossAllBlogInstances ? AllBlogCategories : Categories).FirstOrDefault(category => category.Id == id);
        }

Also in PostViewBase.cs the call to the method in new overloaded function and update of current method with a true to not break the current functionality.
        public virtual string CategoryLinks(string separator)
        {
            return CategoryLinks(separator,true);
        }

        public virtual string CategoryLinks(string separator, bool acrossAllBlogInstances)
        {
            var keywords = new string[this.Post.Categories.Count];
            const string Link = "<a href=\"{0}\">{1}</a>";
            for (var i = 0; i < this.Post.Categories.Count; i++)
            {
                var c = Category.GetCategory(this.Post.Categories[i].Id, acrossAllBlogInstances);
                if (c != null)
                {
                    keywords[i] = string.Format(CultureInfo.InvariantCulture, Link, c.RelativeOrAbsoluteLink, c.Title);
                }
            }

            return string.Join(separator, keywords);
        }

and in your postview.ascx a call to CatelgoyLinks with a false
<p class="categories"><%=CategoryLinks(" | ", false) %></p>
I hope someone will look into the problem further, but for now you have a workaround.