Hi, we're getting the following error message intermittently - at least several times a day - in the file \Sitefinity\UserControls\Navigation\SitePanelbar.ascx.cs . We have made a few customizations to the ItemDataBound method in the file, but we can't quite place what might be happening. Can anyone help us figure out this issue?
Error Message
10/30/2008 1:29:31 PM [UNKNOWN]
************************************************************************************
Exception Type: System.ArgumentException
Message: An item with the same key has already been added.
Source: mscorlib
Stack Trace:
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
at Telerik.Cms.Data.CmsPage.get_LanguageVersions()
at Telerik.Cms.Web.CmsSiteMapProvider.GetChildNodes(SiteMapNode node)
at System.Web.SiteMapNode.get_ChildNodes()
at System.Web.UI.WebControls.SiteMapDataSource.GetNodes()
at System.Web.UI.WebControls.SiteMapDataSource.GetTreeView(String viewPath)
at System.Web.UI.WebControls.SiteMapDataSource.GetHierarchicalView(String viewPath)
at System.Web.UI.HierarchicalDataSourceControl.System.Web.UI.IHierarchicalDataSource.GetHierarchicalView(String viewPath)
at Telerik.RadPanelbarUtils.RadControlDataSource.System.Web.UI.IHierarchicalDataSource.GetHierarchicalView(String viewPath)
at Telerik.WebControls.RadPanelbar.PerformDataBinding(IEnumerable data)
at System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data)
at System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback)
at System.Web.UI.WebControls.DataBoundControl.PerformSelect()
at System.Web.UI.WebControls.BaseDataBoundControl.DataBind()
at UserControls_SitemapPanelbar.Page_Load(Object sender, EventArgs e) in d:\share\webroot\cms\Sitefinity\UserControls\Navigation\SitePanelbar.ascx.cs:line 46
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.AddedControl(Control control, Int32 index)
at System.Web.UI.ControlCollection.Add(Control child)
at Telerik.Cms.Web.InternalPage.CreateChildControls()
at System.Web.UI.Control.EnsureChildControls()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
------------------------------------------------------------------------------------
Here's the code for ItemDataBound:
public void RadPanelbar1_ItemDataBound(object sender, RadPanelbarEventArgs e)
{
CmsSiteMapNode node = e.Item.DataItem as CmsSiteMapNode;
if (this.hideUrlForGroupPages)
{
if (node != null && node.CmsPage.PageType == CmsPageType.Group)
{
e.Item.NavigateUrl = "";
}
}
if (node != null)
{
if (node.HasChildNodes)
{
e.Item.CssClass = "customFocus";
}
}
}
13 Answers, 1 is accepted
Have you tried to change the default language of your web site? Please refer to the Kb Article Changing the default site language to fix your database if this is the case.
Best wishes,
Georgi
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.

<localization defaultProvider="Sitefinity" persistenceMode="QueryString" defaultCulture="en" cultures="en, fr" autoSetClientLanguage="false">
In this case, we believe that the problem is related to requests synchronization - two requests occur at the same page at the very same moment. Here's the workaround:
Override the default CmsSiteMapProvider and override GetChildNodes method:
using System.Web; |
using Telerik.Cms.Web; |
/// <summary> |
/// Summary description for CmsSiteMapProviderFix |
/// </summary> |
public class CmsSiteMapProviderFix : CmsSiteMapProvider |
{ |
public override SiteMapNodeCollection GetChildNodes(SiteMapNode node) |
{ |
lock (this) |
{ |
return base.GetChildNodes(node); |
} |
} |
} |
... and change the type of the SiteMapProvider in the web.config:
<siteMap defaultProvider="CmsSiteMapProvider" enabled="true"> |
<providers> |
<clear/> |
<add name="CmsSiteMapProvider" description="Displays Cms Pages" type="CmsSiteMapProviderFix"/> |
</providers> |
</siteMap> |
The bad side of this approach is that it could affect your web site performance a bit.
This problem is fixed in Sitefinity 3.5, and the code is optimized even more, so the performance will not be affected at all. We recommend you to upgrade your project to our latest version.
All the best,
Georgi
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.

This is really hard to tell, because it depends on your web site size (actually, the number of the pages you have - it is directly related to the size of the Sitemap), and of course the server configuration.
The Lock statement will prevent any parallel execution of the surrounded code:
lock (this) |
{ |
return base.GetChildNodes(node); |
} |
Having that said, when there are two requests at the very same time, which need a result from this code, the first one (well, there is always first after all) will lock this code, and the processing will begin. The second one is put on halt (performance hit) and will wait for the first to finish. Once the result is returned, the lock is released and the second locks it again.
Given the fact that the Sitefinity's Sitemap is loaded in the memory most of the time, this should be relatively fast operation. All the code is doing is returning the child elements of a given node. This is for example, returning the names of all sub-pages of a given page.
I don't expect noticeable to the human slowdown, but it all depends on the number of pages you have, number of requests and server load.
In Sitefinity 3.5 SP1 this is solved with using of different kind of caches.
I apologize that could not help you much and could not answer your question completely, but hope that this give you some insight.
All the best,
Georgi
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.

- Windows Server 2003 Ent, SP2
- 4 x Intel Xeon 3.06GHZ
- 3.75 GB RAM
- 1400+ pages in Sitefinity
- 700,000 hits / day
We do not expect noticeable slowdown with this configuration.
As a side point, we saw that you do not use caching in your web site. The caching will greatly improve your performance. You may refer to the KB article How to optimize the performance of a Sitefinity Web Site for more information.
I think your website would also make great case study. Do you think you could prepare a case study? You have probably checked out the case studies section on the right hand-side of the showcase gallery page but in case you have not you we invite you to. By submitting a case study you would not only contribute to the Sitefinity community and earn Telerik points, but will also gain marketing exposure.
Let us know about your decision.
Regards,
Georgi
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.

As for the caching option, we've disabled caching because keeping it enabled renders our single sign-on solution inoperable -- in the top right-hand area of the page, there should be sign-out / sign-in links along with a personalized link to the account page (which would read, for example, "Dan's Account"); with caching enabled, incorrect information will be displayed in that corner.
As for preparing a case study, I think we could probably do that; I'll discuss it with my team.
One more thing. We've started getting this error again ("item with the same key"), in a different context. I'm posting the stack trace below; can you help us work out what's happening in this case? Thanks in advance (again!)
11/7/2008 10:35:49 AM [UNKNOWN]
************************************************************************************
Exception Type: System.ArgumentException
Message: An item with the same key has already been added.
Source: mscorlib
Stack Trace:
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
at Telerik.Cms.Data.CmsPage.get_LanguageVersions()
at Telerik.Cms.Web.CmsSiteMapNode.get_Title()
at Telerik.Cms.Web.UI.Breadcrumb.InitializeItem(SiteMapNodeItem item)
at System.Web.UI.WebControls.SiteMapPath.CreateItem(Int32 itemIndex, SiteMapNodeItemType itemType, SiteMapNode node)
at System.Web.UI.WebControls.SiteMapPath.CreateControlHierarchy()
at System.Web.UI.WebControls.SiteMapPath.CreateChildControls()
at System.Web.UI.Control.EnsureChildControls()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
------------------------------------------------------------------------------------
Here's an update of the CmsSiteMapProviderFix have we sent you earlier:
using System.Web; using Telerik.Cms.Web; |
public class CmsSiteMapProviderFix : CmsSiteMapProvider |
{ |
public override SiteMapNodeCollection GetChildNodes(SiteMapNode node) |
{ |
lock (this) |
{ |
return base.GetChildNodes(node); |
} |
} |
protected override CmsSiteMapNode CreateSiteMapNode(ICmsPage page) |
{ |
return new CmsSiteMapNodeFix(this, page); |
} |
} |
public class CmsSiteMapNodeFix : CmsSiteMapNode |
{ |
public override string Title |
{ |
get |
{ |
lock (this.Provider) |
{ |
return base.Title; |
} |
} |
set |
{ |
base.Title = value; |
} |
} |
} |
The core of the problem is the same as we already discussed.
Kind regards,
Georgi
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.

Thanks for the fix! We updated CmsSiteMapProviderFix and added the Telerik.Cms assembly reference...but now we get the following error:
Server Error in '/' Application.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1501: No overload for method 'CmsSiteMapNodeFix' takes '2' arguments
Source Error:
Line 21: {
Line 22: Line 23: return new CmsSiteMapNodeFix(this, page);
Line 24: Line 25: }
|
Ah, yes, the constructor was missing. Here is the code again:
using System.Web; |
using Telerik.Cms.Web; |
using Telerik.Cms; |
public class CmsSiteMapProviderFix : CmsSiteMapProvider |
{ |
public override SiteMapNodeCollection GetChildNodes(SiteMapNode node) |
{ |
lock (this) |
{ |
return base.GetChildNodes(node); |
} |
} |
protected override CmsSiteMapNode CreateSiteMapNode(ICmsPage page) |
{ |
return new CmsSiteMapNodeFix(this, page); |
} |
} |
public class CmsSiteMapNodeFix : CmsSiteMapNode |
{ |
public CmsSiteMapNodeFix(CmsSiteMapProvider provider, ICmsPage page) |
: base(provider, page) |
{ |
} |
public override string Title |
{ |
get |
{ |
lock (this.Provider) |
{ |
return base.Title; |
} |
} |
set |
{ |
base.Title = value; |
} |
} |
} |
I hope everything will be fine this time.
Greetings,
Georgi
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.

Yes, this seems to have solved our problems. Many thanks for your help in figuring this out. As for the case study, we'll contact you about it via email.
Thanks
Dan
I am really glad that it did fix the error. I would like to thank you for your cooperation with this issue, and for your decision about the case study.
We will be glad to assist you with anything else, so do not hesitate to contact us again.
Greetings,
Georgi
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.