Wednesday, September 4, 2013

SharePoint 2010: Linq Exception - An item with the same key has already been added.

What?

All of a sudden we started to see a weird exception in our intranet "System.ArgumentException: An item with the same key has already been added." being thrown by a custom web part that shows results that are indexed by SharePoint 2010 Search.


We have a custom control in our intranet that lists out all items in a searchable A-Z format that are indexed by search based on a chosen content type name. Except for one content type, all the results for other content types have been listed by the control with no issues.

Why?

I have been able to fix the issue but could not find out for sure what the reason was behind this issue.

How?

Steps taken to resolve this issue:

Initial thoughts were that the search index got corrupted. So search index has been dropped and rebuilt. But the issue has not been resolved.

Create a duplicate content type "Custom Form 2" with the same fields as "Custom Form" (the erroring content type)
Identified all the documents with the content type "Custom Form" through out the site using a Content Query Web Part and incrementally changed the content type for those documents to "Custom Form 2" in batches.

Ran incremental crawl in CA

After repeating the above process for 3-4 document libraries the error disappeared.

I then reverted the content type for all those documents from "Custom Form 2" to "Custom Form" and then deleted the staging temporary content type "Custom Form 2"

If you ever experience a similar problem, I recommend running a powershell script to replicate the above steps and you may be ok.

Please let me know if someone is able to figure out the root cause for this issue.

No comments:

Post a Comment