Monday, August 13, 2012

How To Fix A duplicate field name “X” was found Error

Problem

If you’ve arrived at my blog with this error then I apologize, you’ve got a tough road ahead of you, there’s no easy fix to this dreaded “A duplicate field name ‘’ was found” error in SharePoint 2010. 
More than likely you’re trying to create a site from a template but you keep getting the “A duplicate field name “ x” was found”.  You’ve tried everything, including deleting the old site template, deleting the field in question from the site and the site collection, and you’ve probably even tried to download and modify the template wsp itself but then you can’t makecab it.

clip_image001

Explanation

I’m not to sure what causes this issue to arise, I’ve come across it about 5 times now and in the case below, where I simply had to fix it, was the first time I attempted to resolve the issue.  My theory is that the error arises when the content type syndication hub delivers a content type and its corresponding fields to a site that was created from a backup on another site collection that already had the content type.  Now that just a a guess and I’m sure you’re more interested in the solution.

You can see the error by renaming the WSP to .CAB

clip_image002
clip_image003

The place where the duplicates exist is the ElementsFields.xml

clip_image004

Here’s my duplicate field, note how the field is listed twice

clip_image005

Solution 1

Delete and rebuild the site from the bottom up.  Sometimes, when dealing with SharePoint, it’s easier to build SharePoint sites from the bottom up as opposed to repairing broken, corrupt, or damaged sites. 

Solution 2

So this solution is not for the weary, it involves downloading the site template and repairing it using Visual Studio.  The first thing you’ll need is a copy of Visual Studio 2010 Professional or greater installed on a SharePoint Server (DO NOT INSTALL ON YOUR PRODUCTION SHAREPOINT SERVER!!!).  With Visual Studio 2010 Professional there’s an import function that will allow you to download a SharePoint site
Download the WSP from the Solutions gallery (in my case it’s located at http://sharepoint/_catalogs/solutions/Forms/AllItems.aspx )

clip_image002

Open Visual Studio and choose the project type “Import SharePoint Solution Package”. 
If you do not see this option then you didn’t read my previous notes that you must install Visual Studio 2010 Professional or greater.

clip_image007

Specify the solution

clip_image008

Allow all items to be imported

clip_image009

The import may take a while

clip_image010
clip_image011

In the solution explorer locate the Elements.xml file

clip_image012

Remove the duplicate field

clip_image013

On the build menu choose “Package”

clip_image014

You may receive a file length error, in my case I had to remove a few files that I included with the solution because I checked the box to include data

clip_image015

If you saved the site as a template and included content, typically the names of the files that are exported will be too long, remove the files and try again. Note that you can remove the files from within Visual Studio. In the screenshot below I cleared all files that were moved with the site.  You will obviously have to re-upload this data when the template is re-created but it certainly does not affect the functionality of the site since it is just data, not settings or configuration.

clip_image016

Locate the newly compiles WSP in the Visual Studio 2010 projects folder in the bin/release or bin/debug directory for your solution (Usually it’s c:\users\username\Documents\Visual Studio 2010\Projects)

Source: http://www.sharepointassist.com/2011/11/05/a-duplicate-field-name-x-was-found/ 

No comments:

Post a Comment