Deploying custom content types for SharePoint 2010 can be quite painful, especially when you are migrating project from SharePoint 2007.
There are few things to add in ContentType elements file, but lots of guys are already mentioning it – Version=”0″ and Inherits=”TRUE” properties need to be added to your XML to make content types come up after feature activation in SharePoint 2010. Sometimes even Overwrite=”TRUE” but honestly I do not understand what this one does and how to use it properly…
But sometimes you still get funky errors and your feature cannot be activated. Usually it errors on feature activation. There are many alternate errors coming such as:
“The parent content type specified by content type identifier 0×0101 …”
“Key cannot be null”
The biggest issue is – there is no sense and no logic in errors that coming. Sometimes there are different errors when you deploy through Visual Studio than when you activate in Powershell. You can spent all day deploying/reactivating and you do not comprehend what the problem is because inconsistency in errors coming up.
Some points to keep in mind:
- Be extremely careful with multiple content type xml files. It is better to use one schema file that will contain all fields and then all content types. Visual Studio controls the order of elements, if it puts content type before fields – activation will fail. If it puts child content type first before parent content type – activation will fail
- Even in one xml file – you still have to be very very careful. I noticed that sometimes, if you have child and parent content type – it is good to place parent content type, then some other content types, and then child content type. If they one after another, it can happen that SharePoint fill give you error “Parent content type not found”
- Every <ContentType> element has to have <FieldRefs /> node, even if no fields are added
- Be careful with <FieldRef> element, finish it with /> and not witl ></FieldRef>
- If you have syntax error in your file, it may result in disappearing of all content types (even out of the box) from Site Content Type list. Don’t panic, when you retract solution they will be back. You just have something nasty in your elements file that corrupts site content types schema