views:

502

answers:

1

I created a way to dynamically add settingsproperty to a .net app.config file. It all works nic, but when I am launching my app the next time I can only see the properties that are created in the designer. How can I load back the properties runtime.

My code for creating the settingsproperty looks the following:

internal void CreateProperty<T>(string propertyName)
{
    string providerName = "LocalFileSettingsProvider";
    System.Configuration.SettingsAttributeDictionary attributes = new SettingsAttributeDictionary();
    System.Configuration.UserScopedSettingAttribute attr = new UserScopedSettingAttribute();

    attributes.Add(attr.TypeId, attr);

    System.Configuration.SettingsProperty prop;
    SettingsProvider provider = ApplicationEnvironment.GlobalSettings.Providers[providerName];

    prop = new System.Configuration.SettingsProperty(
        propertyName,
        typeof(T),
        provider,
        false,
        default(T),
        System.Configuration.SettingsSerializeAs.String,
        attributes,
        false,
        false
    );

    ApplicationEnvironment.GlobalSettings.Properties.Add(prop);
    ApplicationEnvironment.GlobalSettings.Reload(); 
}

When the next run I ask for the settings property I could not find any of the proeprties created previosuly. No matter if I call the ApplicationEnvironment.GlobalSettings.Reload(); or not.

A: 

User defined configuration settings are tied to the assembly version they were created with. If you have a rolling version number (1.0.. for example), You will lose the settings from the last run.

Joe Caffeine