I am using the below code for deleting the event receiver
It works fine for users in admin group, but for users in contributors group i am trying to delete the event receiver by using elevated permission, but it is not deleting the event receiver
private void RemoveEventReceiver(SPList list, bool IsRemove)
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(SPContext.Current.Site.Url))
{
using (SPWeb web = site.OpenWeb())
{
if (!IsRemove)
{
foreach (SPEventReceiverDefinition receiver in list.EventReceivers)
{
if (receiver.Type == SPEventReceiverType.ItemUpdating)
{
web.AllowUnsafeUpdates = true;
try
{
receiver.Delete();
list.Update();
}
catch (Exception ex)
{
//it comes to exception after receiver.Delete() line
}
break;
}
}
}
}
}
});
}
What is the issue here ? i am not able to figure out the reason