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.