SPException “The collection cannot be modified.” when calling SPContentType.Update()

If you are getting the SPException “The collection cannot be modified.” when calling SPContentType.Update() then ensure that the content type you are updating was not retrieved from the SPWeb.AvailableContentTypes collection. Content types retrieved from this collection (as oppose to SPWeb.ContentTypes) are read-only.

The AvailableContentTypes collection gives you all content types available at the web, i.e. including those content types defined at the parent site collection. If you debug and inspect this collection however, you will see that it has a non-public property called ReadOnly and its value is true. Content types retrieved from this collection also have a non-public property Collection.ReadOnly – which is also true.

If you need to update a content type, retrieve it from the SPWeb.ContentTypes collection instead.

Advertisements

About Bernado

Based in Australia, I am a freelance SharePoint and Dynamics CRM developer. I love developing innovative solutions that address business and everyday problems. Feel free to contact me if you think I can help you with your SharePoint or CRM implementation.
This entry was posted in Content Types, SharePoint, SharePoint 2010. Bookmark the permalink.

7 Responses to SPException “The collection cannot be modified.” when calling SPContentType.Update()

  1. foriamstu says:

    Thanks! You just saved me from a debugging nightmare; I was trying to figure out which of my (many) child content types was causing the problem, and why I was getting an SPException instead of one of the error types documented on MSDN: http://msdn.microsoft.com/en-us/library/ms475889.aspx

  2. Sant says:

    Thanks!! really helped me!!!

  3. John Liu says:

    Saved a lot of time & frustration! Thanks a lot.

  4. John Scott says:

    Thanks!!! Saved me from a debugging headache!!

  5. E says:

    Thank you!! You saved a sharepoint newbie!!!

  6. Pingback: Solved collection cannot be modified | Cao Quoc Hung

  7. Matt Pearson says:

    Thanks, this saved me a lot of time!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s