Error Editing Categories

Jan 7, 2010 at 12:07 AM

I had a bunch of categories named like follows

 

A - B
A - C
A - D

I created a new category call A

Then I edited the first two removing the "A - " and making them a parent of A.

I went to my homepage and got an error: 

An entry with the same key already exists.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: An entry with the same key already exists.

Source Error:

The source code that generated this unhandled exception can only be shown when compiled in debug mode. To enable this, please follow one of the below steps, then request the URL:

1. Add a "Debug=true" directive at the top of the file that generated the error. Example:

  <%@ Page Debug="true" %>

or:

2) Add the following section to the configuration file of your application:

<configuration>
   <system.web>
       <compilation debug="true"/>
   </system.web>
</configuration>

Note that this second technique will cause all files within a given application to be compiled in debug mode. The first technique will cause only that particular file to be compiled in debug mode.

Important: Running applications in debug mode does incur a memory/performance overhead. You should make sure that an application has debugging disabled before deploying into production scenario.


Stack Trace:

[ArgumentException: An entry with the same key already exists.]

   System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) +52

   System.Collections.Generic.TreeSet`1.Add(T item) +288

   System.Collections.Generic.SortedDictionary`2.Add(TKey key, TValue value) +144

   Controls.CategoryList.SortCategories() +194

   Controls.CategoryList.BindCategories() +41

   Controls.CategoryList.get_Html() +76

   Controls.CategoryList.RenderControl(HtmlTextWriter writer) +11

   ASP.themes_trifinitehorizon_site_master.__Renderform1(HtmlTextWriter __w, Control parameterContainer) +896

   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +256

   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19

   System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter writer) +8677641

   System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) +32

   System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTextWriter output) +51

   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27

   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99

   System.Web.UI.HtmlControls.HtmlForm.RenderControl(HtmlTextWriter writer) +40

   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +134

   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19

   System.Web.UI.Control.Render(HtmlTextWriter writer) +10

   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27

   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99

   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25

   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +134

   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19

   System.Web.UI.Page.Render(HtmlTextWriter writer) +29

   BlogEngine.Core.Web.Controls.BlogBasePage.Render(HtmlTextWriter writer) +39

   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27

   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99

   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25

   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1266

 


Version Information: Microsoft .NET Framework Version:2.0.50727.4016; ASP.NET Version:2.0.50727.4016

I tried changing it back and that gave me other errors. So I replace the categories.XML on the server. and now I'm getting this:

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

The source code that generated this unhandled exception can only be shown when compiled in debug mode. To enable this, please follow one of the below steps, then request the URL:

1. Add a "Debug=true" directive at the top of the file that generated the error. Example:

  <%@ Page Debug="true" %>

or:

2) Add the following section to the configuration file of your application:

<configuration>
   <system.web>
       <compilation debug="true"/>
   </system.web>
</configuration>

Note that this second technique will cause all files within a given application to be compiled in debug mode. The first technique will cause only that particular file to be compiled in debug mode.

Important: Running applications in debug mode does incur a memory/performance overhead. You should make sure that an application has debugging disabled before deploying into production scenario.


Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]

   admin_Pages_Categories.GetParentTitle(Object item) +158

   ASP.admin_pages_categories_aspx.__DataBind__control16(Object sender, EventArgs e) +78

   System.Web.UI.Control.OnDataBinding(EventArgs e) +99

   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +92

   System.Web.UI.Control.DataBind() +15

   System.Web.UI.Control.DataBindChildren() +211

   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +102

   System.Web.UI.Control.DataBind() +15

   System.Web.UI.Control.DataBindChildren() +211

   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +102

   System.Web.UI.Control.DataBind() +15

   System.Web.UI.WebControls.GridView.CreateRow(Int32 rowIndex, Int32 dataSourceIndex, DataControlRowType rowType, DataControlRowState rowState, Boolean dataBind, Object dataItem, DataControlField[] fields, TableRowCollection rows, PagedDataSource pagedDataSource) +155

   System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding) +2417

   System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +57

   System.Web.UI.WebControls.GridView.PerformDataBinding(IEnumerable data) +14

   System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +114

   System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +31

   System.Web.UI.WebControls.DataBoundControl.PerformSelect() +142

   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +73

   System.Web.UI.WebControls.GridView.DataBind() +4

   admin_Pages_Categories.BindGrid() +94

   admin_Pages_Categories.Page_Load(Object sender, EventArgs e) +38

   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14

   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35

   System.Web.UI.Control.OnLoad(EventArgs e) +99

   System.Web.UI.Control.LoadRecursive() +50

   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627

 


Version Information: Microsoft .NET Framework Version:2.0.50727.4016; ASP.NET Version:2.0.50727.4016

 

Now my site is down. :-(

Any ideas on what to look at to clean this up manually?

Thanks,
-p

Coordinator
Jan 7, 2010 at 4:19 AM

I think right now you probably have child categories pointing to parent categories that no longer exist.

If you're using the default XML storage, then you'll have a categories.xml file in your App_Data folder.  In there, you'll find "parent" attributes that look something like:

parent="19770e74-9ec9-4cde-b2ab-e5051aaaf348"

Clear out the parent values so you end up with just

parent=""

Save the file.  You'll probably need to clear out the data in BE memory for these manual changes to get detected.  If you make any change to the web.config file (add a space, etc), this will clear out data stored in memory, and the latest data will get re-read from the App_Data folder.

FWIW, this is a problem that was fixed after 1.5 was released, and the correct behavior of not allowing this situation to occur will be included in the upcoming BE 1.6 release.

Jan 7, 2010 at 6:01 AM

And fixed... Thank you!

Jan 7, 2010 at 5:56 PM

Actually it was fixed and then with me doing nothing it went back to broken. Here's that error again with debug=true.

I have no parents set in my categories.mxl

 

An entry with the same key already exists.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.ArgumentException: An entry with the same key already exists.

Source Error: 

Line 151:			{
Line 152:				if (HasPosts(cat))
Line 153:					dic.Add(cat.CompleteTitle(), cat.Id);
Line 154:			}
Line 155:


Source File: e:\web\deepplayaco\htdocs\App_Code\Controls\CategoryList.cs    Line: 153 

Stack Trace: 

[ArgumentException: An entry with the same key already exists.]
   System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) +52
   System.Collections.Generic.TreeSet`1.Add(T item) +288
   System.Collections.Generic.SortedDictionary`2.Add(TKey key, TValue value) +144
   Controls.CategoryList.SortCategories() in e:\web\deepplayaco\htdocs\App_Code\Controls\CategoryList.cs:153
   Controls.CategoryList.BindCategories() in e:\web\deepplayaco\htdocs\App_Code\Controls\CategoryList.cs:90
   Controls.CategoryList.get_Html() in e:\web\deepplayaco\htdocs\App_Code\Controls\CategoryList.cs:74
   Controls.CategoryList.RenderControl(HtmlTextWriter writer) in e:\web\deepplayaco\htdocs\App_Code\Controls\CategoryList.cs:181
   ASP.themes_trifinitehorizon_site_master.__Renderform1(HtmlTextWriter __w, Control parameterContainer) in e:\web\deepplayaco\htdocs\themes\trifinitehorizon\site.master:78
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +256
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
   System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter writer) +8677641
   System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) +32
   System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTextWriter output) +51
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
   System.Web.UI.HtmlControls.HtmlForm.RenderControl(HtmlTextWriter writer) +40
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +134
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
   System.Web.UI.Control.Render(HtmlTextWriter writer) +10
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +134
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
   System.Web.UI.Page.Render(HtmlTextWriter writer) +29
   BlogEngine.Core.Web.Controls.BlogBasePage.Render(HtmlTextWriter writer) +39
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1266
Coordinator
Jan 7, 2010 at 6:21 PM

This is same initial error you had yesterday, and is a problem with the CategoryList control that should probably be addressed.

Right now you have 2 or more categories with the same exact name, which is causing this error.

Jan 7, 2010 at 6:28 PM

I just figured it out too. When I was scrubbing the categories.XML file I was only looking for entries with the same GUID. I manually went to the categories admin page and saw the duplicate names and modified one of them now it's working.

Thanks for the help Ben. I'll stop breaking things now. Looking forward to seeing 1.6!