Skip to main content

Cloud

Exception when creating Publishing sites: “The last content type on a list cannot be deleted”

I ran into this exception on a project recently and was stumped. This error showed up whenever we attempted to create new sites using the MOSS publishing site definition, or using any other site definition that included the publishing features:

exception

After the exception was thrown, the site was in a half-provisioned state: the site itself existed and the welcome page had been set to "[SPWebUrl]/Pages/Default.aspx" — but the publishing feature was dying in provisioning the Pages document library, so clicking on the site returned an HTTP 404 result.

Strangely, since the site existed, we could manually navigate to the site’s settings page, activate the publishing feature — and then everything was fine. It seemed like the issue we were seeing was something timing-related during the initial provisioning (which should have been my first clue, as it turned out).

The SharePoint logs revealed this:

   1: Successfully added content type (Name='Page', Id='0x010100C568DB52D9D0A14C96666E9F200794813...<clipped for brevity>
   2: Successfully added content type 'Page' to list 'Pages'.
   3: CreatePagesDocumentLibrary failed. Microsoft.SharePoint.SPException: The last content type on a list cannot be deleted.  

Digging in a little, I reflected the publishing assembly to see what was going on. The upshot was that the publishing feature receiver was blowing up when trying to configure the Pages document library. Internally, it adds the "Page" content type, then tries to remove all of the other content type(s) that got created on the doc lib. You can tell from the exception that something obviously wasn’t going right with adding the "Page" content type. Apparently the logs were lying and the content type really wasn’t being successfully added to the list.

To make a long story short, Microsoft support helped us find our culprit. We had associated a workflow with the "Document" content type in the site collection and set it to propagate to all child content types. It was set to run when new items were created. Since "Page" is a descendant of "Document" in the content type hierarchy, the workflow was kicking off while the publishing feature receiver was running and apparently clobbering the publishing code.

It’s unclear to me at this point whether this is a bug or behavior that’s by design, but in any case, setting the workflow to not start automatically for new items for the "Page" content type ended up being a solution for us. Once we did that, creating sites from site definitions that reference the publishing feature worked fine. I haven’t tried it, but I suspect it might also be possible to test for the condition within the workflow code and handle things gracefully from there.

It was a pretty obscure thing to find — not sure how many others might have a comparable configuration — but I couldn’t find much information online, so hopefully this helps someone who runs into the same exception.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Matthew Morse

More from this Author

Follow Us
TwitterLinkedinFacebookYoutubeInstagram