I have a config file app.exe.config and appSettings section has something like this:
Finally, I have found a solution.
The solution is to declare the config file as this:
And from code
Configuration config = ConfigurationManager.OpenExeConfiguration(Application.ExecutablePath);
AppSettingsSection myAppSettings = config.GetSection("appSettings")
myAppSettings.Settings["var1"].Value = "value 11";
config.Save(ConfigurationSaveMode.Modified);
Note that I use GetSection("appSettings") instead of config.AppSettings.Settings
Thanks to all that help people in StackOverflow.