Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to save custom configuration section to app.config

I'm struggling to save a custom section to my app.config. This is the code I have so far:

            Configuration configuration =     ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

            //Read the TunnelSection from the configuration file
            TunnelSection tunnels = ConfigurationManager.GetSection("TunnelSection") as TunnelSection;


            HostConfigElement newhost = new HostConfigElement();

            newhost.Password = "hola";
            newhost.SSHPort = 22;
            newhost.SSHServerHostname = "holahola";

            TunnelConfigElement newtunnel = new TunnelConfigElement();

            newtunnel.LocalPort = 12;
            newtunnel.RemotePort = 12;
            newtunnel.Name = "12";
            newtunnel.DestinationServer = "12";

            TunnelCollection newtunnelcollection = new TunnelCollection();

            newtunnelcollection.Add(newtunnel);

            newhost.Tunnels = newtunnelcollection;

            tunnels.Tunnels.Add(newhost);             

            ConfigurationManager.RefreshSection("TunnelSection");

            configuration.Save(ConfigurationSaveMode.Full);

The issue is that the config file is not being modified. If I loop through the TunnelSection, I see that the new host has been added.

To rule out permissions issues, I tried adding a setting to appsettings like this:

configuration.AppSettings.Settings.Add("hola", "hola");

and this works fine.

I also tried saveas but to no avail.

Any ideas? TIA

like image 236
yomismo Avatar asked Nov 14 '22 20:11

yomismo


1 Answers

System Settings cannot be modified but user settings can be. User settings are not saved on application directory but saved under /appData//. Please check at that location

like image 65
hungryMind Avatar answered Feb 01 '23 14:02

hungryMind