I am having problems registering some eventreceivers of the contenttype form. Content and recipients have been deployed and registered by me, so I am not trying to remove any MOSS built-in or internal tools.
I am trying to archive this with the following code snippet:
using (SPSite site = new SPSite("http://wssdev06/"))
{
using (SPWeb web = site.RootWeb)
{
SPContentType type = web.AvailableContentTypes[<ContentTypeName>];
while (type.EventReceivers.Count > 0)
{
type.EventReceivers[0].Delete();
}
type.Update();
}
}
Unfortunately, the command "type.Update ()" throws an exception, telling me that the collection cannot be changed. As you can see in the code, I have already tried different things to solve this problem, as I allow insecure updates or run this code with elevated privileges. But I always get the same exception.
So what am I doing wrong?