Failed to save custom configuration section in app.config

I am trying to save a custom section in my app.config. This is the code that I still have:

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 problem is that the configuration file does not change. If I go through TunnelSection, I see that a new host has been added.

To eliminate permission issues, I tried adding a parameter to appsettings as follows:

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

and it works great.

I also tried saveas, but to no avail.

Any ideas? TIA

+4
source share
1 answer

System settings cannot be changed, but user settings can be made. User settings are not saved in the application directory, but stored in / appData //. Please check in this place.

+1
source

All Articles