1
votes

I have a feature in Sharepoint 2010 that adds a SPWebConfigModification to the sharepoint site. It adds a key to the appSettings section

Feature activation Code is as follows:

private static void ActivateWebConfigModifications(SPWebApplication webApplication)
    {
        webApplication.WebConfigModifications.Add(GetConfigMod());

        webApplication.Update();
        webApplication.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications();
    }

Feature Deactivation code is as follows:

private static void DeactivateWebConfigModifications(SPWebApplication webApplication)
    {
        Collection<SPWebConfigModification> modifications = webApplication.WebConfigModifications;

        foreach (SPWebConfigModification mod in modifications)
        {
            if (mod.Owner == GetConfigMod().Owner)
            {
                modifications.Remove(mod);
            }
        }

        webApplication.Update();
        webApplication.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications(); 
    }

Problem and sequence of events.

1) Deploy wsp solution with feature. Success

2) Examine WebConfig file for correct appsetting entry. appSettings entry is correct

3) Retract and remove wsp solution. Retract and remove Success

4) Edit value of WebConfigModification in feature code

5) Deploy wsp with feature containing new value. Success

6) Examine WebConfig file for correct appsetting entry. appSettings entry contains new value.

7) In central admin, deactivate feature. Success

8) Activate Feature. Success

9) Examine WebConfig file for correct appsetting entry. appSettings entry contains OLD Value.

Why does the old value persist?

When examining the WebConfigModifications using powershell I find that the old value is present in the collection when the following code is run in Powershell:

Add-PSSnapin Microsoft.SharePoint.PowerShell
$w = Get-SPWebApplication -Identity http://SiteUrl
$w.WebConfigModifications

Any Ideas?

1

1 Answers

0
votes

This looks like a caching problem, PowerShell caches a lot of SharePoint objects, including site templates. It also does not reload updated dll's in the GAC. What I normally do after a deployment of a wsp is close all PowerShell windows, and restart iis and the owstimer.