Content Type SPI bug in SharePoint Sandbox Solutions

Content Type SPI bug in SharePoint Sandbox Solutions

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:

  1. Create a new Empty SharePoint Project (Sandboxed Solution)
  2. Add a Content Type SPI to the project inheriting from Item
  3. Add a new List Definition to the project (Custom List) and choose to add a List Instance
  4. Add the DisallowContentTypes=”FALSE”tag to the Elements.xml for the list
  5. Add the EnableContentTypes=”TRUE” tag to the List Definition Schema.xml
  6. Remove all ContentTypeRefElements from the Schema.xml
  7. Add a ContentTypeRef Element for the Content Type created above to the <ContentTypes>Element
  8. Create a Feature Receiver and add code into the FeatureActivatedevent to enable Content Types on the list
  9. 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.

List Settings page

List Content Type Information

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.

Thanks! Open-mouthed smile

3 thoughts on “Content Type SPI bug in SharePoint Sandbox Solutions

  1. Reggie

    Hey,

    Yes you CAN enable content types declaratively in sandboxed solutions!

    I was able to do it on many occasions. The problem is that there are many ways to mess it up so it seems impossible. It’s almost that all the planets need to be aligned.

    I may comment on this later to give more detail but from what I gather you need to:

    1. add EnableContentTypes=”TRUE” attibute to the List element in your schema.xml (this you talked about)
    2. you list template and list instance have to be in a feature that has a web scope. Visual studio will allow you to scope it to the site collection and everything will behave properly but when you click the new button in the ribbon it will say “new item” and not the name of you content type.

    now this is where it seems to be blurry for me.

    3. all your fields have to be declared properly in your schema.xml

    I’ll try to comment later if I get more information.

    You may consider using code to enable content types if your lists have lookup fields that you are declaring. Otherwise you will need to have multiple features.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">