Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

"An item with the same key has already been added" error while publishing an entity

(0) ShareShare
ReportReport
Posted on by 50

We are in the process of upgrading our application from CRM 4.0 to CRM 2015 and currently in CRM 2013. While trying to publish the JavaScript changes for one of the main entity, we are receiving this error and the publish fails. We checked most of the posts regarding similar issue and tried out all the options. But nothing resolves the issue.

Since this is one of the main entity of the application, it has around 600 attributes and 100+ relationships. Recreating the entity would be difficult.

Service Pack 1 installation succeeded but the database updates failed. While trying to update the organization through Deployment Manager, the wizard throws the same error. Below is the stack trace from deployment manager.

09:20:45| Error| Installer Complete: OrganizationDatabaseHotFixer - Error encountered
09:20:45| Error| Exception occured during Microsoft.Crm.Tools.Admin.OrganizationDatabaseHotFixer: Error.ActionFailed Microsoft.Crm.Tools.Admin.InstallDatabaseUpdatesAction
InnerException:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> 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 Microsoft.Crm.ObjectModel.StringMapPublisher.RetrieveExistingStringMaps(Int32 objectTypeCode, ICollection attributes, Int32 langId)
at Microsoft.Crm.ObjectModel.StringMapPublisher.UpdateStringMaps(EntityMetadata entity, Int32 langId)
at Microsoft.Crm.ObjectModel.StringMapPublisher.PublishStringMaps()
at Microsoft.Crm.ObjectModel.PublishXml.PublishDuringSetup(ExecutionContext context)
at Microsoft.Crm.SE.DllMethodActions.ImportSystemSolution.PublishStringStatusMapsRibbonData()
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
at Microsoft.Crm.Setup.Database.DllMethodAction.Execute(Guid organizationId)
at Microsoft.Crm.Setup.Database.DatabaseInstaller.ExecuteReleases(ReleaseInfo releaseInfo, Boolean isInstall)
at Microsoft.Crm.Setup.Database.DatabaseInstaller.Install(Int32 languageCode, String configurationFilePath, Boolean upgradeDatabase, Boolean isInstall)
at Microsoft.Crm.Setup.Database.DatabaseInstaller.InstallUpdate(String configurationFilePath, Boolean upgradeDatabase)
at Microsoft.Crm.Setup.Common.Update.DBUpdateDatabaseInstaller.ApplyDBUpdates(Guid orgId)
at Microsoft.Crm.Tools.Admin.InstallDatabaseUpdatesAction.ApplyDBUpdatesInternal(Guid orgId, String orgUniqueName, String releaseFilePath, Boolean ignoreErrors)
at Microsoft.Crm.Tools.Admin.InstallDatabaseUpdatesAction.ApplyDBUpdates(Guid orgId, String orgUniqueName, OrganizationOperationType operationType)
at Microsoft.Crm.Tools.Admin.InstallDatabaseUpdatesAction.Do(IDictionary parameters)
at Microsoft.Crm.Setup.Shared.CrmAction.ExecuteAction(CrmAction action, IDictionary parameters, Boolean undo)
InnerException:
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 Microsoft.Crm.ObjectModel.StringMapPublisher.RetrieveExistingStringMaps(Int32 objectTypeCode, ICollection attributes, Int32 langId)
at Microsoft.Crm.ObjectModel.StringMapPublisher.UpdateStringMaps(EntityMetadata entity, Int32 langId)
at Microsoft.Crm.ObjectModel.StringMapPublisher.PublishStringMaps()
at Microsoft.Crm.ObjectModel.PublishXml.PublishDuringSetup(ExecutionContext context)
at Microsoft.Crm.SE.DllMethodActions.ImportSystemSolution.PublishStringStatusMapsRibbonData()

09:20:45| Info| Setting organization state. New state = Failed
09:20:46| Error| Update Organization with Id=ed29ebf2-193a-e711-bcb4-005056b4365f failed with Exception:
System.Exception: Error.ActionFailed Microsoft.Crm.Tools.Admin.InstallDatabaseUpdatesAction ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> 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 Microsoft.Crm.ObjectModel.StringMapPublisher.RetrieveExistingStringMaps(Int32 objectTypeCode, ICollection attributes, Int32 langId)
at Microsoft.Crm.ObjectModel.StringMapPublisher.UpdateStringMaps(EntityMetadata entity, Int32 langId)
at Microsoft.Crm.ObjectModel.StringMapPublisher.PublishStringMaps()
at Microsoft.Crm.ObjectModel.PublishXml.PublishDuringSetup(ExecutionContext context)
at Microsoft.Crm.SE.DllMethodActions.ImportSystemSolution.PublishStringStatusMapsRibbonData()
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
at Microsoft.Crm.Setup.Database.DllMethodAction.Execute(Guid organizationId)
at Microsoft.Crm.Setup.Database.DatabaseInstaller.ExecuteReleases(ReleaseInfo releaseInfo, Boolean isInstall)
at Microsoft.Crm.Setup.Database.DatabaseInstaller.Install(Int32 languageCode, String configurationFilePath, Boolean upgradeDatabase, Boolean isInstall)
at Microsoft.Crm.Setup.Database.DatabaseInstaller.InstallUpdate(String configurationFilePath, Boolean upgradeDatabase)
at Microsoft.Crm.Setup.Common.Update.DBUpdateDatabaseInstaller.ApplyDBUpdates(Guid orgId)
at Microsoft.Crm.Tools.Admin.InstallDatabaseUpdatesAction.ApplyDBUpdatesInternal(Guid orgId, String orgUniqueName, String releaseFilePath, Boolean ignoreErrors)
at Microsoft.Crm.Tools.Admin.InstallDatabaseUpdatesAction.ApplyDBUpdates(Guid orgId, String orgUniqueName, OrganizationOperationType operationType)
at Microsoft.Crm.Tools.Admin.InstallDatabaseUpdatesAction.Do(IDictionary parameters)
at Microsoft.Crm.Setup.Shared.CrmAction.ExecuteAction(CrmAction action, IDictionary parameters, Boolean undo)
--- End of inner exception stack trace ---

Any help would be greatly appreciated. Thanks.

*This post is locked for comments

  • Suggested answer
    Nishant Rana Profile Picture
    Nishant Rana 55 Microsoft Employee on at
    RE: "An item with the same key has already been added" error while publishing an entity

    Thanks for sharing this, we faced similar issue nishantrana.me/.../

  • Verified answer
    surajcs55 Profile Picture
    surajcs55 50 on at
    RE: "An item with the same key has already been added" error while publishing an entity

    We contacted Microsoft and the issue got resolved. :)

    Microsoft checked their internal function and noticed that the system is  concatenating a few strings together in order to create a key: entity object type code + Field schema name + option value + language code + option label.

    When the form publish was executed, there were 2 optionset fields that had their options concatenated, resulting in 1 duplicate:

    1) 10023 + new_wire_currencytype + 21 + 1033 + AUD = 10023new_wire_currencytype211033AUD

    2) 10023 + new_wire_currencytype2 + 1 + 1033 + AUD = 10023new_wire_currencytype211033AUD

    Removed one of the option and things started working fine.

  • surajcs55 Profile Picture
    surajcs55 50 on at
    RE: "An item with the same key has already been added" error while publishing an entity

    Tried the script posted in the links. Still the same issue :(

  • RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: "An item with the same key has already been added" error while publishing an entity

    I found this previous post community.dynamics.com/.../130119 which contains a support KB for this same issue. Try this. Do take a back up before running the script.

    support.microsoft.com/.../a-404-error-occurs-when-attempting-to-access-a-microsoft-dynamics-crm

    The below blog also mentioned few tips on handling this error. Take a look if the above doesn't help

    www.powerobjects.com/.../troubleshooting-solution-import-errors

  • surajcs55 Profile Picture
    surajcs55 50 on at
    RE: "An item with the same key has already been added" error while publishing an entity

    Yes Ravi. I do have the option to update the database from Deployment Manager. But when I run it, it fails with the same error. Please find the error log below.

    02:51:58|Verbose| Validation ran.

    02:51:58|Verbose| Validation completed.

    02:51:58|Verbose| Method exit: Microsoft.Crm.Tools.EDW.Framework.EDWTool.Run

    02:51:58|Verbose| Method exit: Microsoft.Crm.Tools.EDW.Framework.EDWTool.RunAll

    02:51:58|Verbose| Method entry: Microsoft.Crm.Tools.EDW.Framework.EDWToolCallbacks.Clear

    02:51:58|Verbose| Method exit: Microsoft.Crm.Tools.EDW.Framework.EDWToolCallbacks.Clear

    02:52:06|Verbose| Retrieving database base language code Provider=SQLOLEDB;Data Source=tmi-7devsql001\TMI;Initial Catalog=TMI_MSCRM;Integrated Security=SSPI ...

    02:52:06|   Info| Database base language code: 1033.

    02:52:06|   Info| Installer Start: OrganizationDatabaseHotFixer.Install: operation DatabaseHotFix

    02:52:06|   Info| Executing Install action: Microsoft.Crm.Tools.Admin.InstallDatabaseUpdatesAction

    02:52:06|Verbose| Retrieving database base language code Provider=SQLOLEDB;Data Source=tmi-7devsql001\TMI;Initial Catalog=TMI_MSCRM;Integrated Security=SSPI ...

    02:52:06|   Info| Database base language code: 1033.

    02:52:06|   Info| Applying latest dbUpdates to organization.  Id=ed29ebf2-193a-e711-bcb4-005056b4365f, UniqueName=TMI.

    02:52:50|   Info| CrmAction execution time; InstallDatabaseUpdatesAction; 00:00:43.8446731

    02:52:50|  Error| Installer Complete: OrganizationDatabaseHotFixer - Error encountered

    02:52:50|  Error| Exception occured during Microsoft.Crm.Tools.Admin.OrganizationDatabaseHotFixer: Error.ActionFailed Microsoft.Crm.Tools.Admin.InstallDatabaseUpdatesAction

    InnerException:

    System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> 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 Microsoft.Crm.ObjectModel.StringMapPublisher.RetrieveExistingStringMaps(Int32 objectTypeCode, ICollection attributes, Int32 langId)

      at Microsoft.Crm.ObjectModel.StringMapPublisher.UpdateStringMaps(EntityMetadata entity, Int32 langId)

      at Microsoft.Crm.ObjectModel.StringMapPublisher.PublishStringMaps()

      at Microsoft.Crm.ObjectModel.PublishXml.PublishDuringSetup(ExecutionContext context)

      at Microsoft.Crm.SE.DllMethodActions.ImportSystemSolution.PublishStringStatusMapsRibbonData()

      --- End of inner exception stack trace ---

      at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)

      at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)

      at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)

      at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)

      at Microsoft.Crm.Setup.Database.DllMethodAction.Execute(Guid organizationId)

      at Microsoft.Crm.Setup.Database.DatabaseInstaller.ExecuteReleases(ReleaseInfo releaseInfo, Boolean isInstall)

      at Microsoft.Crm.Setup.Database.DatabaseInstaller.Install(Int32 languageCode, String configurationFilePath, Boolean upgradeDatabase, Boolean isInstall)

      at Microsoft.Crm.Setup.Database.DatabaseInstaller.InstallUpdate(String configurationFilePath, Boolean upgradeDatabase)

      at Microsoft.Crm.Setup.Common.Update.DBUpdateDatabaseInstaller.ApplyDBUpdates(Guid orgId)

      at Microsoft.Crm.Tools.Admin.InstallDatabaseUpdatesAction.ApplyDBUpdatesInternal(Guid orgId, String orgUniqueName, String releaseFilePath, Boolean ignoreErrors)

      at Microsoft.Crm.Tools.Admin.InstallDatabaseUpdatesAction.ApplyDBUpdates(Guid orgId, String orgUniqueName, OrganizationOperationType operationType)

      at Microsoft.Crm.Tools.Admin.InstallDatabaseUpdatesAction.Do(IDictionary parameters)

      at Microsoft.Crm.Setup.Shared.CrmAction.ExecuteAction(CrmAction action, IDictionary parameters, Boolean undo)

    InnerException:

    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 Microsoft.Crm.ObjectModel.StringMapPublisher.RetrieveExistingStringMaps(Int32 objectTypeCode, ICollection attributes, Int32 langId)

      at Microsoft.Crm.ObjectModel.StringMapPublisher.UpdateStringMaps(EntityMetadata entity, Int32 langId)

      at Microsoft.Crm.ObjectModel.StringMapPublisher.PublishStringMaps()

      at Microsoft.Crm.ObjectModel.PublishXml.PublishDuringSetup(ExecutionContext context)

      at Microsoft.Crm.SE.DllMethodActions.ImportSystemSolution.PublishStringStatusMapsRibbonData()

    02:52:50|   Info| Setting organization state.  New state = Failed

    02:52:50|  Error| Update Organization with Id=ed29ebf2-193a-e711-bcb4-005056b4365f failed with Exception:

    System.Exception: Error.ActionFailed Microsoft.Crm.Tools.Admin.InstallDatabaseUpdatesAction ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> 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 Microsoft.Crm.ObjectModel.StringMapPublisher.RetrieveExistingStringMaps(Int32 objectTypeCode, ICollection attributes, Int32 langId)

      at Microsoft.Crm.ObjectModel.StringMapPublisher.UpdateStringMaps(EntityMetadata entity, Int32 langId)

      at Microsoft.Crm.ObjectModel.StringMapPublisher.PublishStringMaps()

      at Microsoft.Crm.ObjectModel.PublishXml.PublishDuringSetup(ExecutionContext context)

      at Microsoft.Crm.SE.DllMethodActions.ImportSystemSolution.PublishStringStatusMapsRibbonData()

      --- End of inner exception stack trace ---

      at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)

      at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)

      at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)

      at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)

      at Microsoft.Crm.Setup.Database.DllMethodAction.Execute(Guid organizationId)

      at Microsoft.Crm.Setup.Database.DatabaseInstaller.ExecuteReleases(ReleaseInfo releaseInfo, Boolean isInstall)

      at Microsoft.Crm.Setup.Database.DatabaseInstaller.Install(Int32 languageCode, String configurationFilePath, Boolean upgradeDatabase, Boolean isInstall)

      at Microsoft.Crm.Setup.Database.DatabaseInstaller.InstallUpdate(String configurationFilePath, Boolean upgradeDatabase)

      at Microsoft.Crm.Setup.Common.Update.DBUpdateDatabaseInstaller.ApplyDBUpdates(Guid orgId)

      at Microsoft.Crm.Tools.Admin.InstallDatabaseUpdatesAction.ApplyDBUpdatesInternal(Guid orgId, String orgUniqueName, String releaseFilePath, Boolean ignoreErrors)

      at Microsoft.Crm.Tools.Admin.InstallDatabaseUpdatesAction.ApplyDBUpdates(Guid orgId, String orgUniqueName, OrganizationOperationType operationType)

      at Microsoft.Crm.Tools.Admin.InstallDatabaseUpdatesAction.Do(IDictionary parameters)

      at Microsoft.Crm.Setup.Shared.CrmAction.ExecuteAction(CrmAction action, IDictionary parameters, Boolean undo)

      --- End of inner exception stack trace ---

      at Microsoft.Crm.Setup.Shared.CrmAction.ExecuteAction(CrmAction action, IDictionary parameters, Boolean undo)

      at Microsoft.Crm.Setup.Shared.Installer.Install(IDictionary stateSaver)

      at Microsoft.Crm.Tools.Admin.OrganizationOperation.Install(IDictionary stateSaver)

      at Microsoft.Crm.Tools.Admin.OrganizationOperation.Execute()

      at Microsoft.Crm.Tools.Admin.OrganizationDatabaseHotFixer.Execute()

      at Microsoft.Crm.Tools.Admin.ApplyDatabaseHotFixInstaller.ApplyDatabaseHotFix(IApplyDatabaseHotFixInfo applyDatabaseHotFixInfo)

    02:52:50|   Info| Found the older table DBUpdateInstallInfo_V5, updating new table and deleting

    02:52:50|   Info| GetDBUpdateRevisionThresholdForServer(): Threshold = 6.1.0005.0111.

  • RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: "An item with the same key has already been added" error while publishing an entity

    Okay, this confirm that it is related to your version. If you go to deployment manager, do you updates available for the organization. If yes, can you click and see if you can update the database. Its been long I logged into CRM server but I guess the option si somewhere on the right side to update.

  • surajcs55 Profile Picture
    surajcs55 50 on at
    RE: "An item with the same key has already been added" error while publishing an entity

    Hi Ravi,

    The async service is up and running. We had installed all the updates for 2013. However for all the updates, we are getting a error "The Update Rollup 2 for Microsoft Dynamics CRM Server Service Pack 1 (KB2963850) completed successfully. However, the database update failed for some organizations".

    The same error "item with same key" is thrown in all the log files for the updates.

    Anything that can be done from the database side? Please advise.

    1513.CRM.jpg

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: "An item with the same key has already been added" error while publishing an entity

    Hi,

    I am pretty sure it is not related to your JavaScript as it is coming from server while performing changes(insterting new record) to stringmap.

    You mentioned in your post that you are currently on CRM 2013. Can you check if you asyn service is running? There was a bug which fixed in update 2.0 with the same error message-

    support.microsoft.com/.../update-rollup-2-for-microsoft-dynamics-crm-2013-service-pack-1

    This is not directly related to your issue but it is possible that it is a bug in the current version of your CRM 2013 which is fixed in later updates. I would suggest to download/apply the latest update for CRM 2013 and then try again.

    Hope this helps.

  • surajcs55 Profile Picture
    surajcs55 50 on at
    RE: "An item with the same key has already been added" error while publishing an entity

    I commented the entire JavaScript code and tried publishing the entity. Still the error remains :(

    Any idea why?

  • Sreevalli Profile Picture
    Sreevalli 3,256 on at
    RE: "An item with the same key has already been added" error while publishing an entity

    Since the issue with javascript changes, try removing the suspected functions and keep trying to publish. once we get the function which causing issue, then it will be more easy to spotout the field.

    I know its heard for the key entities with lots for customization but I couldnt see any other way

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans