I'm trying to create several content types via code, and they are all inheriting from a custom content type which was previously deployed.
Here's the weird part, i can deploy once from Visual studio 2010 or power shell, but after that first time i get duplicate content type error. (yes i clean out everything, remove lists, CT's, features, empty both trash cans, solution etc.)
I can still activate the features from the SharePoint GUI and it'll add and remove the CT's as intended. Just not working from VS deploy or PS feature activation.
Here's the code i'm using:
using (SPSite site = ((SPSite)properties.Feature.Parent))
{ SPWeb rootweb = site.RootWeb;
...
CreateContentType(rootweb, "0x01010053E1D612BA3F4E21AA250ECD751942B300EBAAF2332BAA478FBECFAC0FB1BAB611", "group1", "ctName", fieldList);
0x0101 <- base
00
53E1D612BA3F4E21AA250ECD751942B3 <- parent
00
EBAAF2332BAA478FBECFAC0FB1BAB611 <- new content type guid
public static void CreateContentType(SPWeb web, string contentTypeId, string contentTypeGroup, string contentTypeName, List<String> fieldList)
{
if (web.ContentTypes[contentTypeName] == null)
{
try
{
SPContentType contentType = new SPContentType(new SPContentTypeId(contentTypeId), web.ContentTypes, contentTypeName);
if (contentType != null)
{
web.ContentTypes.Add(contentType); //create the content type
contentType.Group = contentTypeGroup;
foreach (string field in fieldList) //assigns fields to the content type
{
SharePointUtils.AssignFieldToContentType(web, contentType, field);
}
contentType.Update();
}
web.Update();
}
catch (Exception ex)
{
LoggingService.LogError(CategoryId.General, ex.Message);
}
}
}
Found this explanation on the web:
A DB update is mentioned (which is out of the question) and also a powershell script: http://www.mattjimison.com/blog/2011/06/21/a-duplicate-content-type-found-error/
Ran the script and it ups the "NextChildByte" for the parent CT but it doesn't help.
"MSS 2010/Foundation February 2012 Cumulative Update" didn't help either.
What is the difference between activating a feature from Power Shell and activating it from the SP GUI?