Hi,
I've got some problems unregistering some eventreceivers form a contenttype. The contenttype and the receivers were deployed and registered by myself so I don't try to remove any MOSS built-in or internal eventreceivers.
I trying to archive this with the following code snippet:
using (SPSite site = new SPSite("http://wssdev06/"))
{
using (SPWeb web = site.RootWeb)
{
// web.AllowUnsafeUpdates = true;
SPContentType type = web.AvailableContentTypes[<ContentTypeName>];
while (type.EventReceivers.Count > 0)
{
type.EventReceivers[0].Delete();
}
type.Update();
// web.AllowUnsafeUpdates = false;
}
}
Unfortunately the command "type.Update()" throws an exception telling me that the collection cannot be modified. As you can see in the code I've already tried different things to solve this problem, as allowing unsafe updates or running this code with elevated privileges. But I always get the same exception.
So what am I doing wrong?