We have a strange situation where we have managed to get two copies of a custom content type referenced in a document library.
The content types had the same name and content type ID, and this ID was that of the content type in the gallery. Usually a content type referred to in a list will have a child ID of the one that is held in the gallery.
The original occurrence of this issue was successfully resolved by removing the last instance of each of these duplicates from each affected document library.
//where contentTypeId and contentTypeName are defined for a duplicate
var contentTypes = from ct in documentLibrary.ContentTypes.Caset<SPContentTypes>()
where ct.Id.Equals(contentTypeId) && ct.Name.Equals(contentTypeName)
select ct;
contentTypes.Last().Delete();
The problem has returned and this time two different content types have both been duplicated in affected document libraries.
When trying to reuse the previous approach to delete either of the "Content Type A" duplicates we get an error - "A duplicate content type "Content Type B" was found"
The opposite issue occurs when trying to delete "Content Type B", so it would seem that each duplicate is preventing the other from being fixed. It also stops any management of content types in these libraries.
Is it possible to batch up deletions of content types to skip around the validation? I was wondering SPWeb.ProcessBatchData() would be any use but it seems woefully underdocumented.
As an aside, the cause of this issue is in a third party piece of software - a fix is being pursued