In simplified form, I have the following situation.
A Parent content type
<ContentType ID="0x0100db5b9dac9c5f4d098820f922eebf3b39"
Name="Parent"
Group="Example Content Types"
Description="Parent Content Type"
Inherits="TRUE"
Version="0">
<FieldRefs>
<FieldRef ID="{3822302b-cff8-4f7c-bcc0-de1540cb7447}"
Name="FirstParentField" />
<FieldRef ID="{D1BBFFB1-A7DE-4DC8-B013-3D06E7D6FAAF}"
Name="SecondParentField" />
</FieldRefs>
</ContentType>
with the following fields
<Field ID="{3822302b-cff8-4f7c-bcc0-de1540cb7447}"
Type="Text"
Name="FirstParentField"
DisplayName="First Parent Field"
Group="Example Columns"
Overwrite="TRUE" />
<Field ID="{D1BBFFB1-A7DE-4DC8-B013-3D06E7D6FAAF}"
Type="Text"
Name="SecondParentField"
DisplayName="Second Parent Field"
Group="Example Columns"
Overwrite="TRUE" />
and a child content type defined as
<ContentType ID="0x0100db5b9dac9c5f4d098820f922eebf3b39005fc63c83e67045908707c64645d4db55"
Name="Child"
Group="Example Content Types"
Description="Child Content Type"
Inherits="TRUE"
Version="0">
<FieldRefs>
<RemoveFieldRef ID="{D1BBFFB1-A7DE-4DC8-B013-3D06E7D6FAAF}"
Name="SecondParentField" />
<FieldRef ID="{5C3ADD2C-2196-4C79-8117-EEBCD453DD5F}"
Name="ChildField" />
</FieldRefs>
</ContentType>
with the following field
<Field ID="{5C3ADD2C-2196-4C79-8117-EEBCD453DD5F}"
Type="Text"
Name="ChildField"
DisplayName="Child Field"
Group="Example Columns"
Overwrite="TRUE" />
The idea is to hide the one of the parent's fields in the child content type while retaining the other.
As many of you will no doubt know, this does not work. The reason being XML declarations can only state how the object is. By trying to remove an inherited field reference I am stating the this is like the parent with a slight modification -- the modification not being allowed.
So, in an attempt to get around this limitation, I added the following
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
using (var web = ((SPSite)properties.Feature.Parent).RootWeb)
{
var child = web.AvailableContentTypes["Child"];
child.Update();
}
}
thinking if I forced the update, the modification declared in the XML would be applied.
This throws an SPException is thrown stating 'The collection cannot be modified.'
Could you help me understand what collection is failing to be modified and why?