I seem to have come across what I believe to be a bug when with Content Types in SharePoint 2010 Sandbox Solutions. I believe this bug to be caused by Visual Studio but I haven’t been able to confirm this yet. The issue arises when you provision a Content Type on a list definition declaratively, when I say declaratively I mean include the ContentTypeRef Element in the List Definition Schema.xml. You cannot enable Content Types on a list declaratively so I am using some code in the FeatureActivated event to do this.
When the solution is deployed the Content Type will be correctly provisioned on the list but it will have the same name as the list and it will inherit from System rather than Item or whichever parent Content Type it should inherit from.
Originally I thought it was an issue with my environment so I recreated a fresh SharePoint farm on a Virtual Machine and the issue still exists. My environment is setup as follows:
- Windows Server 2008 R2 64-bit SP1
- SQL 2008 R2 64-bit
- SharePoint 2010 SP1 (14.0.6029.1000)
- Visual Studio 2010 SP1
To reproduce this issue follow the steps below:
- Create a new Empty SharePoint Project (Sandboxed Solution)
- Add a Content Type SPI to the project inheriting from Item
- Add a new List Definition to the project (Custom List) and choose to add a List Instance
- Add the DisallowContentTypes=”FALSE”tag to the Elements.xml for the list
- Add the EnableContentTypes=”TRUE” tag to the List Definition Schema.xml
- Remove all ContentTypeRefElements from the Schema.xml
- Add a ContentTypeRef Element for the Content Type created above to the <ContentTypes>Element
- Create a Feature Receiver and add code into the FeatureActivatedevent to enable Content Types on the list
- Deploy the solution
Observe that on visiting the List Settings page for the list that the Content Type has been added but has the wrong name (same name as the list) and inherits from System and not Item.
I would be grateful if someone can confirm whether or not this is a bug, by design or something that is not supported in Sandbox solutions.
You can obtain the Visual Studio project containing the code that I have created to replicate this issue here.