Listen SharePoint – the content type ISN’T part of an application feature

I have been having another couple of days of head-bashing. (If that had been head-banging, and had involved a particularly good concert, I would have been over the moon.) But no. It was “bashing” – as in brick wall – and again it involved my current frenemy, SharePoint.

After a not-so-good period when a new virus managed to run riot over the network servers, resulting in me rebuilding my SharePoint development environment (and getting it all best practice-y – yay me!), I started again with my library solution.

I deployed the solution to a test site via Visual Studio 2013, did a bit of testing, retracted the solution, made some changes, and tried to deploy it again. I say “try”, because there was an error during deployment about how VS couldn’t delete the content type.

Cue Google search mania.

The majority of people recommend the following if you receive this error:

  • Ensure the content type is no longer related to a list / library
  • If you have deleted the list / library, make sure you have also removed it from the site recycle bin and the site collection recycle bin (Site Settings | Site Collection Administration > Recycle bin)

I tried all of that, and still I got stuck with a Content Type that wouldn’t delete. When trying to delete through the UI, SharePoint gave me the error:

The content type [insert content type name here] is part of an application feature.

Well, clearly it wasn’t as I’d already retracted the solution and its features.

More Googling.

Someone recommended the incredibly helpful tool SharePoint Manager, which allows a user to see what might be using their tenacious content type. However, upon checking the usage count, it was – you guessed it – a bit fat zero. Nothing was using it. Which should mean it could be deleted, but it just wouldn’t go!

Back to the drawing board.

Some people had the helpful suggestion of deleting the entire site and recreating. I get that you might get away with that in a development environment, but how does that help if you get this issue in production? I needed a better solution. But, in order to try to find it, I deleted the site and recreated, and tried again with the deploying of the solution.

Here’s what I tried:

Test 1

  • Deploy the solution.
  • Don’t create a new app – in fact, don’t do anything with it.
  • Retract the solution.
  • Result: the content type goes away

Test 2

  • Deploy the solution
  • Create a new app, but don’t add any documents, or do anything else with it.
  • Delete the app (library).
  • Delete the library from the recycle bin.
  • Empty the Site Collection recycle bin (even though nothing was in it).
  • Retract the solution.
  • Result: the content type is stuck and giving the message about being part of a feature again.

Test 3 (having deleted and recreated the site again)

  • Deploy the solution
  • Create a new app. This time, I played around with the library, as it didn’t seem to make any difference to what the content type was going to do; just the action of creating my app (a library that used that content type) was enough to ensure the content type overstayed its welcome.
  • Go to the library settings and add a new content type (in my case, “Document” – the parent content type).
  • Delete the custom content type from the library, leaving only “Document”.
  • Just for good measure, I also removed the custom columns from the library.
  • Delete the library.
  • Delete the library from the recycle bin.
  • Empty the Site Collection recycle bin (even though nothing was in it).
  • Deactivate the features one-by-one (the list template, the content type, the site columns)
  • (When I paused to check on the Content Type at this stage, I discovered it had gone!!)
  • Retract the solution.
  • Result: the content type goes away!

I know it seems a bit of a palava, but if it works to remove the content type, it works for me! This means no deletion and recreation of site, and no (completely unsupported and severely discouraged) editing of the SharePoint database in order to tell SharePoint the content type is NOT part of an application feature, whatever it thinks.

Hope this helps someone else who is trying to detach their SharePoint site from a content type that refuses to leave.

if (feelLikeTalking) { leaveAComment(thanks); }