System.ArgumentException: An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at umbraco.macro.GetXsltExtensionsImpl()
at umbraco.macro.b__4()
at umbraco.cms.businesslogic.cache.Cache.GetCacheItem[TT](String
cacheKey, Object syncLock, CacheItemPriority priority,
CacheItemRemovedCallback refreshAction, CacheDependency cacheDependency,
TimeSpan timeout, GetCacheItemDelegate`1 getCacheItem)
at umbraco.macro.GetXsltExtensions()
at umbraco.macro.AddMacroXsltExtensions()
at umbraco.presentation.webservices.codeEditorSave.SaveXslt(String
fileName, String oldName, String fileContents, Boolean ignoreDebugging)
Could you please ellaborate a bit more on these errors - then it will be much more easy for people to try and help you out and the replies you will get will be of much better quality.
So a couple of things that would be good to know in order to help you out
What version of Umbraco are you using?
Is this happening on a fresh install?
Have you made an upgrade from an older version to a newer version?
Have you made a custom XSLT extension or other custom code?
When did this start to happen?
Have you installed some package that could be the cause?
I had this exact same problem on Sunday. I have a site that is working in production, but I pulled the latest code from my HG repository to work on it locally. I backed up the DB and restored it locally. So, it should be an identical version to what is running. Every macro that calls a XSLT file gives this duplicate key exception. I even tried to pull down the code on a different laptop with the same results.
I have tried to update to 4.7.1.1 (was on 4.7.1) and that did not help. I am using SQL Express as the back end. I have tried to touch the web.config to flush the cache and that did not help either. I can try to reproduce later this evening and give more details.
Do you know if there has been made any custom xslt extensions or some user controls that could be causing this?
If you see the xslt renderings errors it can be caused by a reference missing in the xsltExtensions.config file. It can also be caused by some of the dll files mentioned in the post Jeroen is linking to above.
I don't have any of the legacy dlls, this site started with 4.7.0 then upgraded to 4.7.1. I also checked and I don't have any missing references in the xslt extensions config file. I even tried to comment out all of the extensions and that did not help either.
I can reproduce this by either loading a page referencing ANY XSLT macro, or by trying to save the XSLT in the backoffice. I am stuck on this one. I have tried everything I can think of. I guess next I'll have to get the source and try to debug umbraco core to see if it gives me any more information.
Here is the trace info in case it helps anyone.
Category
Message
From First(s)
From Last(s)
aspx.page
Begin PreInit
umbracoInit
handling request
2.95654737682387E-05
0.000030
request handler
current url ''
0.000140025368819019
0.000110
umbracoRequestHandler
xpath: '/root/*'
0.000176982211029318
0.000037
umbracoRequestHandler
xpath: '/root/* [@urlName = ""] | /root/*'
0.000192996842653781
0.000016
umbracoRequestHandler
xpath: '/root/* [@urlName = ""] | /root/*'
0.000213117790079387
0.000020
umbracoRequestHandler
Just before xPath query (False, '/root/* [@urlName = ""] | /root/*')
0.000228721790123736
0.000016
umbracoRequestHandler
pageXPathQueryStart: '/root'
0.000242272632267512
0.000014
umbracoRequestHandler
After xPath query
0.000277176316577238
0.000035
umbracoRequestHandler
Access checking started
0.00030797368508582
0.000031
umbracoRequestHandler
Page not protected
0.000328505264091541
0.000021
umbracoRequestHandler
Access checking ended
0.000342056106235317
0.000014
umbracoInit
Done handling request
0.00035807073785978
0.000016
umbracoPage
Element loaded: siteName
0.000543676212071501
0.000186
umbracoPage
Element loaded: bodyText
0.000583096843762486
0.000039
umbracoPage
Pagedata loaded for Home (ID: 1099)
0.000600343370127292
0.000017
umbracoPage
Looking up skin information
0.00062990884389553
0.000030
default.aspx
Culture changed to en-US
0.000794161475941301
0.000164
aspx.page
End PreInit
0.000935418739500664
0.000141
aspx.page
Begin Init
0.000980177581733136
0.000045
item
Start parsing 'pageName'
0.0010134387397224
0.000033
item
Done parsing 'pageName'
0.00105984010827534
0.000046
item.recursive
Item loaded from 1099
0.00112554116109364
0.000066
item
Start parsing 'siteName'
0.00114443021377891
0.000019
item
Done parsing 'siteName'
0.00116947874016589
0.000025
item.recursive
Item loaded from 1099
0.0012039717928955
0.000034
item
Start parsing 'siteName'
0.00121957579293985
0.000016
item
Done parsing 'siteName'
0.00124626684564728
0.000027
renderMacro
Rendering started (macro: Top Navigation, type: 1, cacheRate: 0)
0.00185728663685755
0.000611
umbracoMacro
Before adding extensions
0.00196733590032822
0.000110
umbracoMacro InnerException
An item with the same key has already been added. An item with the same key has already been added. at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) at umbraco.macro.GetXsltExtensionsImpl() at umbraco.macro.<GetXsltExtensions>b__4() at umbraco.cms.businesslogic.cache.Cache.GetCacheItem[TT](String cacheKey, Object syncLock, CacheItemPriority priority, CacheItemRemovedCallback refreshAction, CacheDependency cacheDependency, TimeSpan timeout, GetCacheItemDelegate`1 getCacheItem) at umbraco.macro.GetXsltExtensions() at umbraco.macro.AddMacroXsltExtensions() at umbraco.macro.GetXsltTransformResult(XmlDocument macroXML, XslCompiledTransform xslt, Dictionary`2 parameters) at umbraco.macro.loadMacroXSLT(macro macro, MacroModel model, Hashtable pageElements)
0.103393746820172
0.101426
renderMacro
Rendering started (macro: Slider Images, type: 1, cacheRate: 0)
0.104344769559717
0.000951
umbracoMacro
Before adding extensions
0.104450712507386
0.000106
umbracoMacro InnerException
An item with the same key has already been added. An item with the same key has already been added. at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) at umbraco.macro.GetXsltExtensionsImpl() at umbraco.macro.<GetXsltExtensions>b__4() at umbraco.cms.businesslogic.cache.Cache.GetCacheItem[TT](String cacheKey, Object syncLock, CacheItemPriority priority, CacheItemRemovedCallback refreshAction, CacheDependency cacheDependency, TimeSpan timeout, GetCacheItemDelegate`1 getCacheItem) at umbraco.macro.GetXsltExtensions() at umbraco.macro.AddMacroXsltExtensions() at umbraco.macro.GetXsltTransformResult(XmlDocument macroXML, XslCompiledTransform xslt, Dictionary`2 parameters) at umbraco.macro.loadMacroXSLT(macro macro, MacroModel model, Hashtable pageElements)
I solved it for my instance. The problem was that I have created a Web Application project to maintain my project in Visual Studio. I also use the XSLTSearch package. When I created my web app project, I copied teh XsltSearch.cs class into the App_Code folder of my web application. Because this file had the build action set to compile it was compiled into Mysite.umbraco.dll (my web application's dll) AND a dynamically compiled by asp.net due to the fact that it was in the ASP.NET App_Code folder.
So, when umbraco runs the following bit of code in umbraco.presentation.macro.GetXsltExtensionsImpl(), the system returns two instances of XSLTSearch. Since this class is decorated with the XsltExtension attribute, it will find this class in both assemblies and try to add both items to the collection of XsltExtensions.
// zb-00042 #29949 : do not hide errors, refactorforeach (Type xsltType in BusinessLogic.Utils.TypeFinder.FindClassesMarkedWithAttribute(typeof(XsltExtensionAttribute)))
{
object[] tpAttributes = xsltType.GetCustomAttributes(typeof(XsltExtensionAttribute), true);
foreach (XsltExtensionAttribute tpAttribute in tpAttributes)
{
string ns = !string.IsNullOrEmpty(tpAttribute.Namespace) ? tpAttribute.Namespace : xsltType.FullName;
extensions.Add(ns, Activator.CreateInstance(xsltType));
}
}
To fix the problem, I was able to just move that XsltSearch.cs out of the App_Code folder, thus there was only one version (the one that got compiled into my web app's dll.
If you are still having this problem, check for any classes decorated with the [XsltExtension] attribute instead of in the /config/xsltExtensions.config file.
-- No, I am already uploaded site on server. its working fine, but on thrusday I added some functionality for this installed pagkages uComponent, PDCalendar...
and then uninstall PDCalendar as no use of this so..
its working fine on local but when upload it on live all xslt files gives error..
Have you made an upgrade from an older version to a newer version?
-- No
Have you made a custom XSLT extension or other custom code?
-- No
When did this start to happen?
-- after installing pagkages uComponent, PDCalendar... i think so..
Have you installed some package that could be the cause?
-- uComponent, PDCalendar... but remove PDCalendar..
Have you checked the to see if the uComponents XSLT extensions (if you installed that part of the package) have been referenced in the xsltConfig.config file? In the /config folder.
An item with the same key has already been added.
Hello,
Error occured
System.ArgumentException: An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at umbraco.macro.GetXsltExtensionsImpl()
at umbraco.macro.b__4()
at umbraco.cms.businesslogic.cache.Cache.GetCacheItem[TT](String cacheKey, Object syncLock, CacheItemPriority priority, CacheItemRemovedCallback refreshAction, CacheDependency cacheDependency, TimeSpan timeout, GetCacheItemDelegate`1 getCacheItem)
at umbraco.macro.GetXsltExtensions()
at umbraco.macro.AddMacroXsltExtensions()
at umbraco.presentation.webservices.codeEditorSave.SaveXslt(String fileName, String oldName, String fileContents, Boolean ignoreDebugging)
I got error everywhere...
Error parsing XSLT file:
Hi Jignesh
Could you please ellaborate a bit more on these errors - then it will be much more easy for people to try and help you out and the replies you will get will be of much better quality.
So a couple of things that would be good to know in order to help you out
Looking forward to hear more from you :)
/Jan
Did you upgrade from an older Umbraco version? If all your xslt files give an error it could be this: http://our.umbraco.org/forum/ourumb-dev-forum/bugs/18381-All-xslt-files-broken-after-upgrading-to-47
Jeroen
I had this exact same problem on Sunday. I have a site that is working in production, but I pulled the latest code from my HG repository to work on it locally. I backed up the DB and restored it locally. So, it should be an identical version to what is running. Every macro that calls a XSLT file gives this duplicate key exception. I even tried to pull down the code on a different laptop with the same results.
I have tried to update to 4.7.1.1 (was on 4.7.1) and that did not help. I am using SQL Express as the back end. I have tried to touch the web.config to flush the cache and that did not help either. I can try to reproduce later this evening and give more details.
Hi Justin
Do you know if there has been made any custom xslt extensions or some user controls that could be causing this?
If you see the xslt renderings errors it can be caused by a reference missing in the xsltExtensions.config file. It can also be caused by some of the dll files mentioned in the post Jeroen is linking to above.
/Jan
I don't have any of the legacy dlls, this site started with 4.7.0 then upgraded to 4.7.1. I also checked and I don't have any missing references in the xslt extensions config file. I even tried to comment out all of the extensions and that did not help either.
I can reproduce this by either loading a page referencing ANY XSLT macro, or by trying to save the XSLT in the backoffice. I am stuck on this one. I have tried everything I can think of. I guess next I'll have to get the source and try to debug umbraco core to see if it gives me any more information.
Here is the trace info in case it helps anyone.
An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at umbraco.macro.GetXsltExtensionsImpl()
at umbraco.macro.<GetXsltExtensions>b__4()
at umbraco.cms.businesslogic.cache.Cache.GetCacheItem[TT](String cacheKey, Object syncLock, CacheItemPriority priority, CacheItemRemovedCallback refreshAction, CacheDependency cacheDependency, TimeSpan timeout, GetCacheItemDelegate`1 getCacheItem)
at umbraco.macro.GetXsltExtensions()
at umbraco.macro.AddMacroXsltExtensions()
at umbraco.macro.GetXsltTransformResult(XmlDocument macroXML, XslCompiledTransform xslt, Dictionary`2 parameters)
at umbraco.macro.loadMacroXSLT(macro macro, MacroModel model, Hashtable pageElements)
An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at umbraco.macro.GetXsltExtensionsImpl()
at umbraco.macro.<GetXsltExtensions>b__4()
at umbraco.cms.businesslogic.cache.Cache.GetCacheItem[TT](String cacheKey, Object syncLock, CacheItemPriority priority, CacheItemRemovedCallback refreshAction, CacheDependency cacheDependency, TimeSpan timeout, GetCacheItemDelegate`1 getCacheItem)
at umbraco.macro.GetXsltExtensions()
at umbraco.macro.AddMacroXsltExtensions()
at umbraco.macro.GetXsltTransformResult(XmlDocument macroXML, XslCompiledTransform xslt, Dictionary`2 parameters)
at umbraco.macro.loadMacroXSLT(macro macro, MacroModel model, Hashtable pageElements)
I solved it for my instance. The problem was that I have created a Web Application project to maintain my project in Visual Studio. I also use the XSLTSearch package. When I created my web app project, I copied teh XsltSearch.cs class into the App_Code folder of my web application. Because this file had the build action set to compile it was compiled into Mysite.umbraco.dll (my web application's dll) AND a dynamically compiled by asp.net due to the fact that it was in the ASP.NET App_Code folder.
So, when umbraco runs the following bit of code in umbraco.presentation.macro.GetXsltExtensionsImpl(), the system returns two instances of XSLTSearch. Since this class is decorated with the XsltExtension attribute, it will find this class in both assemblies and try to add both items to the collection of XsltExtensions.
To fix the problem, I was able to just move that XsltSearch.cs out of the App_Code folder, thus there was only one version (the one that got compiled into my web app's dll.
If you are still having this problem, check for any classes decorated with the [XsltExtension] attribute instead of in the /config/xsltExtensions.config file.
Thanks,
Justin
Hi Jan Skovgaard
What version of Umbraco are you using?
-- V4.7.1
Is this happening on a fresh install?
-- No, I am already uploaded site on server. its working fine, but on thrusday I added some functionality for this installed pagkages uComponent, PDCalendar...
and then uninstall PDCalendar as no use of this so..
its working fine on local but when upload it on live all xslt files gives error..
Have you made an upgrade from an older version to a newer version?
-- No
Have you made a custom XSLT extension or other custom code?
-- No
When did this start to happen?
-- after installing pagkages uComponent, PDCalendar... i think so..
Have you installed some package that could be the cause?
-- uComponent, PDCalendar... but remove PDCalendar..
also delete dll for pdcalendar from bin..
Thanks..
Hi Jignesh
Sorry for my late reply on this one.
Have you checked the to see if the uComponents XSLT extensions (if you installed that part of the package) have been referenced in the xsltConfig.config file? In the /config folder.
/Jan
Brilliant, thanks so much... deleting XsltSearch.cs from App_Code solved this one for me. :)
Thanks Justin, it helped me to solve same problem here (custom .cs with xsltattribute) after moving to another server.
is working on a reply...