Psconfig failure with error - An item with the same key has already been added

On the other day I was working on a psconfig failure issue after MOSS SP2 installation.

The psconfig upgrade command line was failing immediately and hence no upgrade logs was generated.

Below was the stack trace:

-----------------------------------------------------------------------------------------------------------------

Exception: 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 System.Collections.Generic.Dictionary`2.System.Collections.IDictionary.Add(Object key, Object value)

   at Microsoft.SharePoint.Administration.SPAutoSerializingObject.DeserializeBasicObject(XmlElement xmlValue)

   at Microsoft.SharePoint.Administration.SPAutoSerializingObject.SetStateXml(XmlNodeList childNodes)

   at Microsoft.SharePoint.Administration.SPAutoSerializingObject.SetStateXml(XmlDocument value)

   at Microsoft.SharePoint.Administration.SPPersistedObject.Initialize(SPConfigurationDatabase configurationDatabase, Guid id, Guid parentId, String name, SPObjectStatus status, Int64 version, XmlDocument state)

   at Microsoft.SharePoint.Administration.SPConfigurationDatabase.GetObject(Guid id, Guid parentId, Guid type, String name, SPObjectStatus status, Byte[] versionBuffer, String xml)

   at Microsoft.SharePoint.Administration.SPConfigurationDatabase.GetObject(SqlDataReader dr)

   at Microsoft.SharePoint.Administration.SPConfigurationDatabase.RefreshCache(Int64 currentVersionOverride, List`1& newObjects, List`1& deletedObjects, Int64& newestObjectVersion)

   at Microsoft.SharePoint.Administration.SPConfigurationDatabase.RefreshCache()

   at Microsoft.SharePoint.PostSetupConfiguration.Farm.RefreshCacheAndUpdate(TaskBase task)

   at Microsoft.SharePoint.PostSetupConfiguration.UpgradeBootstrapTask.Run()

   at Microsoft.SharePoint.PostSetupConfiguration.TaskThread.ExecuteTask()

--------------------------------------------------------------------------------------------------------------------

Since the upgrade log was not getting generated, hence reviewed the ULS and the event logs.

Noticed below error many a times in the ULS logs

The SPPersistedObject with Name ABC_7d94e326-919e-4aa1-9577-b1549c028a81, Id bf7a2181-d667-4da7-ab96-896ed5bcf638, Parent e6ee5401-e263-40d5-a3b1-ab4a90ee20bb failed to initialize with the following error: 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 System.Collections.Generic.Dictionary`2.System.Collections.IDictionary.Add(Object key, Object value) at Microsoft.SharePoint.Administration.SPAutoSerializingObject.DeserializeBasicObject(XmlElement xmlValue) at Microsoft.SharePoint.Administration.SPAutoSerializingObject.SetStateXml(XmlNodeList childNodes) at Microsoft.SharePoin...

------------------------------------------------------------------------------------------------------------------------

Below were the errors in the Event Log:

Event Type: Error

Event Source: Office SharePoint Server

Event Category: Office Server Shared Services

Event ID: 6480

Date: 10/9/2009

Time: 7:29:46 PM

User: N/A

Computer: ############

Description:

An exception occurred while executing the alternate url synchronizer job.

Reason: An item with the same key has already been added.

Techinal Support Details:

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 System.Collections.Generic.Dictionary`2.System.Collections.IDictionary.Add(Object key, Object value)

   at Microsoft.SharePoint.Administration.SPAutoSerializingObject.DeserializeBasicObject(XmlElement xmlValue)

   at Microsoft.SharePoint.Administration.SPAutoSerializingObject.SetStateXml(XmlNodeList childNodes)

   at Microsoft.SharePoint.Administration.SPAutoSerializingObject.SetStateXml(XmlDocument value)

   at Microsoft.SharePoint.Administration.SPPersistedObject.Initialize(SPConfigurationDatabase configurationDatabase, Guid id, Guid parentId, String name, SPObjectStatus status, Int64 version, XmlDocument state)

   at Microsoft.SharePoint.Administration.SPConfigurationDatabase.GetObject(Guid id, Guid parentId, Guid type, String name, SPObjectStatus status, Byte[] versionBuffer, String xml)

   at Microsoft.SharePoint.Administration.SPConfigurationDatabase.GetObject(SqlDataReader dr)

   at Microsoft.SharePoint.Administration.SPConfigurationDatabase.RefreshCache(Int64 currentVersionOverride, List`1& newObjects, List`1& deletedObjects, Int64& newestObjectVersion)

   at Microsoft.SharePoint.Administration.SPConfigurationDatabase.RefreshCache()

   at Microsoft.SharePoint.Administration.SPConfigurationDatabase.StoreObject(SPPersistedObject obj, Boolean storeClassIfNecessary, Boolean ensure)

   at Microsoft.SharePoint.Administration.SPConfigurationDatabase.PutObject(SPPersistedObject obj, Boolean

*****************************************************************************************

Event Type: Error

Event Source: Windows SharePoint Services 3

Event Category: Timer

Event ID: 6398

Date: 10/9/2009

Time: 7:29:45 PM

User: N/A

Computer: ############

Description:

The Execute method of job definition Microsoft.SharePoint.Administration.SPConfigurationRefreshJobDefinition (ID 31cc6fc1-2aef-4fe6-b248-e594f6e57961) threw an exception. More information is included below.

An item with the same key has already been added.

For more information, see Help and Support Center at https://go.microsoft.com/fwlink/events.asp.

*****************************************************************************************

Event Type: Error

Event Source: Windows SharePoint Services 3

Event Category: Timer

Event ID: 6398

Date: 10/9/2009

Time: 7:29:46 PM

User: N/A

Computer: ###############

Description:

The Execute method of job definition Microsoft.Office.Server.Administration.AlternateUrlSynchronizerJob (ID a60272bc-65da-4322-b9cb-50bdb5f73b88) threw an exception. More information is included below.

An item with the same key has already been added.

For more information, see Help and Support Center at https://go.microsoft.com/fwlink/events.asp.

****************************************************************************************

Ran the following query:

SELECT Id, ClassId, ParentId, Name, Status, Version, Properties FROM Objects

From the results of the above query, searched for the “ABC_7d94e326-919e-4aa1-9577-b1549c028a81” and found an entry for the same.

Since the event log was also showing errors related to “URL” and “AlternateUrlSynchronizerJob” , checked properties column of the Object.

There was an entry for “Microsoft.SharePoint.Administration.SPAlternateUrlCollection”

Ran the same above query on a Out of the Box test server farm and found that “Microsoft.SharePoint.Administration.SPAlternateUrlCollection” is available inside the Objects table under the config DB as many times the count of SharePoint Web applications.

For example if we have 4 web applications, we should see 4 entries of “Microsoft.SharePoint.Administration.SPAlternateUrlCollection” under the Objects table.

But at customers end there was an extra entry with the name “ABC_7d94e326-919e-4aa1-9577-b1549c028a81”.

This seemed to be an orphan entry.

Hence we used

“stsadm.exe -o deleteconfigurationobject –id”

to delete the orphan web application ID.

After deleting the orphan entry, the psconfig progressed from Step 2 and started to upgrade the databases.