5

I've created a custom list with one content type inherited from 'Schedule' (no additional fields). Now I need to add one more content type to the instance of that list in the feature activated event (this content type is also inherited from 'Schedule' and has some additional fields including several taxonomy fields).

the following piece of code: myCustomList.ContentTypes.Add(myCustomContentType); generates the following error: A duplicate field name "{78190EDB-029C-42d3-A22A-498FE43D9EC0}" was found.

Piece of stack trace:

[SPException: A duplicate field name "78190edb-029c-42d3-a22a-498fe43d9ec0" was found.]
   Microsoft.SharePoint.SPFieldLinkCollection.Add(SPFieldLink fieldLink) +1445
   Microsoft.SharePoint.SPContentType.UpdateFieldsCollection(Dictionary`2 cachedFields, Guid addedField) +521
   Microsoft.SharePoint.SPContentType.ProvisionFieldOnList(SPField field, Boolean bRecurAllowed) +2355
   Microsoft.SharePoint.SPContentType.ProvisionFieldsOnList() +634
   Microsoft.SharePoint.SPContentType.DeriveContentType(SPContentTypeCollection cts, SPContentType& ctNew) +671
   Microsoft.SharePoint.SPContentTypeCollection.AddContentTypeToList(SPContentType contentType) +2319
   Microsoft.SharePoint.SPContentTypeCollection.AddContentType(SPContentType contentType, Boolean updateResourceFileProperty, Boolean checkName, Boolean setNextChildByte) +242
   Microsoft.SharePoint.SPContentTypeCollection.Add(SPContentType contentType) +24
   Microsoft.SharePoint.ApplicationPages.AddContentTypeToListPage.Update(Object o, EventArgs e) +835
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +103
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +140
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +32
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3103

The 'GUID' is a GUID of a taxonomy hidden text field. Here is it:

<Field ID="{78190EDB-029C-42d3-A22A-498FE43D9EC0}"
       Name="MyTaxonomyFieldNameTaxHTField0"
       StaticName="MyTaxonomyFieldNameTaxHTField0"
       DisplayName="MyTaxonomyFieldNameTaxHTField0"
       Group="MyGroupName"
       Type="Note"
       ShowInViewForms="FALSE"
       CanToggleHidden="TRUE"
       Hidden="TRUE"/>

I tried recreating the whole web application, changing the GUID of the field...the same thing occurs with any taxonomy hidden text field included in content type (and it doesn't matter if I'm doing it programmatically or through the web. All taxonomy fields itself are activated properly.

4
  • Is the missing " on Group a typo? May 20, 2013 at 9:59
  • No, sry, my fault! Updated May 20, 2013 at 10:17
  • not a proper answer, but until someone post something better, have a look at this link - The second part describe a taxonomy related problem. Seems that your issue could depend on the field getting detached from the metadata store?
    – SPArcheon
    May 20, 2013 at 11:21
  • Well, all this remove, fix and enable helped. BUT this code shouldn't be in feature activated event. What is causing this problem? Why everything is fine, if including this content type in list scheme? May 20, 2013 at 13:19

1 Answer 1

1

I have stumbled upon a similar issue and found a workaround for the issue. What I did was write a loop that tries to create the column and with a try catch construction, removes the duplicate column in the catch clause. I encountered the issue when trying to create a taxonomy site column with the same description as an existing column.

bool createSucceeded = false;
while (!createSucceeded)
{
    try
        {
            field = _rootWeb.Fields.AddFieldAsXml(fieldXml, addToDefaultView, SP.AddFieldOptions.AddFieldInternalNameHint);
            ClientContext.ExecuteQuery();
            createSucceeded = true;
        }
    catch (ServerException ex)
    {
        if (ex.Message.Contains("A duplicate field name"))
        {
            var splitMessage = ex.Message.Split(new[] {'\"'}, StringSplitOptions.RemoveEmptyEntries);
            var duplicateName = splitMessage[1];
            DeleteSiteColumn(duplicateName);
        }
        else
        {
            throw;
        }
    }
}
public void DeleteSiteColumn(string name)
{
    var siteColumn = _rootWeb.Fields.GetByInternalNameOrTitle(name);
    if (siteColumn == null) return;
    siteColumn.DeleteObject();
    ClientContext.ExecuteQuery();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.