Tuesday 31 January 2012

SharePoint 2010 : Item has already been added. Key in dictionary: 'domain\account' Key being added: 'domain\account'

Scenario

The client was migrating from one domain to another. As such the servers in the their SharePoint farm would no longer sit on domainA, they would site on domain. There were many steps to this which I hope to outline in another blog post. A problem occurred when looking at service account migration.
The farm service account had been updated to “domainB\farm” using stsadm as had other service accounts.

Problem

The problem arose when we navigated to http://CentralAdmin/_admin/ManagedAccounts.aspx and http://intranetstg:1111/_admin/FarmCredentialManagement.aspx. In certain scenarios the following error would be displayed:

Item has already been added. Key in dictionary: 'domain\account' Key being added: 'domain\account'

There seemed to be multiple entries for the same account. This was confirmed by running PowerShell “Get-spmanagedaccount” to list them all. I attempted to delete the accounts using “Remove-spmanagedaccount” but the same error occurred

Solution explanation

I found a number of articles explaining ways to fix it but none of the worked for me.  The idea of re-installing the farm seemed over the top. I decided to configure the farm to only use one account throughout as a temporary measure. A new account was created and all components where a previous account had been set were configured to use the temporary account. This was set via http://centraladmin/_admin/FarmCredentialManagement.aspx. (The account for each component was noted so they could be reapplied once the troublesome accoutns were removed). Occasionally the error would occur again after applying but an IIS reset seemingly resolved this.  Once all the components (including farm account) were using the temporary account I could then view all the managed accounts again with PowerShell “Get-spmanagedaccount”. It was then just a matter of deleting all the managed accounts other than the temporary one with “Remove-spmanagedaccount”. It is worth noting here that after each delete an IISreset is required. SharePoint seems to get confused as to what accounts are still present and to which domain they belong to without this. Once only one account was left, new accounts were reregistered and applied to the relevant components via http://centraladmin/_admin/FarmCredentialManagement.aspx. Great.

Solution steps
  1. Create new temporary domain account (domain\temp)
  2. Set this account to be farm account with stsadm -o updatefarmcredentials -userlogin domain\temp -password temp.
  3. Set all other components to use this account in http://centraladmin/_admin/FarmCredentialManagement.aspx (iis resets if error reoccurs)
  4. List and remove accounts other that temp account with powershell ” Get-spmanagedaccount” and Remove-spmanagedaccount” (iis resets if error reoccurs – also watch for domain name changes after reset).
  5. Recreate managed accounts and assign to relevant components again.
  6. Tidy up permissions in SQL (temporary account is probably still hanging around which can be removed).
  7. Relax with Coffee if before 4pm otherwise potentially have a beer.


5 comments:

  1. We had this exact problem, but the solution was much simpler.
    1. run Powershell get-spmanagedaccount to list all the accounts, note the duplicate.
    2. run Powershell remove-spmanagedaccount DOMAIN\account for the account with duplicate (this will only remove one of the duplicated accounts)
    3. IISRESET
    4. Continue to http://centraladmin/_admin/FarmCredentialManagement.aspx as usual.

    ReplyDelete
    Replies
    1. Hi Andy, Thanks for you comment. I said in my post, I did try to remove the account with remove-spmanagedaccount but I got the same error. I therefore had to find an alternative solution as outlined. Glad you got yours fixed quicker though :)

      Delete
  2. thanks alot...the solution steps helpd me alot... once again thanks....

    ReplyDelete
  3. The "MySharedContext" Web Part appears to be causing a problem. Item has already been added. Key in dictionary: '117593' Key being added: '117593'
    I see this error with one of my users , the moment we add in common with you webpat on her profile page. Please help me how to get rid of it.
    thanks,
    Sari

    ReplyDelete
  4. I finally got his fixed, by reviewing this link:

    http://sharepointgoose.blogspot.com/2012/08/getting-error-item-has-already-been.html

    However, when I get to this command:

    Remove-SPManagedAccount $acc[0]

    I had to use:

    Remove-SPManagedAccount $acc[1]

    which deletes the second account

    ReplyDelete