I'm writing a web application scoped feature receiver to make changes to web.config using SPWebConfigModification. Adding entries is working well. My problem is removing the entries. When stepping through the debugger, I can see them being discovered by Owner name and removed from the WebConfigModifications collection. However, on inspection of the web.config file, these entries are still present. In my ULS I can see the FeatureReceiver running and completing for FeatureDeactivating. There are no other entries.
Does anyone have any ideas on what to do to?
public override void FeatureDeactivating(SPFeatureReceiverProperties properties){
SPWebApplication webApp = properties.Feature.Parent as SPWebApplication;
Collection<SPWebConfigModification> modsToRemove = new Collection<SPWebConfigModification>();
foreach (SPWebConfigModification mod in webApp.WebConfigModifications)
{
if (mod.Owner == "MyUniqueName")
modsToRemove.Add(mod);
}
if (modsToRemove.Count > 0)
{
int count = modsToRemove.Count;
for (int i = 0; i < count; i++)
{
webApp.WebConfigModifications.Remove(modsToRemove[i]);
webApp.Update();
}
webApp.WebService.ApplyWebConfigModifications();
}
}