édit: voir dernier message.

Bonjour,

J'ai trouvé un tuto pour utiliser appConfig, et quelques sujet sur le forum...

Cela dit, je n'arrive toujours pas à comprendre un comportement :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 
        private void MDITestImport_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (e.CloseReason == CloseReason.UserClosing)
            {
                string logEtat = logToolStripMenuItem.Checked.ToString();//False
                string LogOld = ConfigurationManager.AppSettings["log"];//True
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                config.AppSettings.Settings.Remove("log");
                config.AppSettings.Settings.Add("log", logEtat);
                config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("appSettings");
                LogOld = ConfigurationManager.AppSettings["log"];//False
                //-
                e.Cancel = false;
            }
        }
et voici ce qu'il y a dans appConfig :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?xml version="1.0" encoding="utf-8" ?>
<configuration>

  <configSections>
    <sectionGroup name="monGroupe">
      <section name ="params" type="System.Configuration.DictionarySectionHandler"/>
      <section name ="unNom" type="System.Configuration.DictionarySectionHandler"/>
    </sectionGroup>
  </configSections>
  
  <connectionStrings>
    <add name=.../>
  </connectionStrings>

  <appSettings>
    <add key="log" value="True"/>
  </appSettings>

  <monGroupe>
    <params>
      <add key="maj" value="" />
    </params>

    <unNom>
      <add key="laClef" value="laValeur" />
    </unNom>
  </monGroupe>
    
</configuration>
Pourtant, la valeur "log" reste toujours à "True" ! Je regarde dans le fichier .exe.config du répertoire debug (et je suis bien en débug), de toute façon même si je ne regarde pas le bon fichier, au 2ème lancement l'execution prouve que la valeur n'a pas été enregistré !

Pourquoi "LogOld = ConfigurationManager.AppSettings["log"];//False" change bien d'état (et c'est ce que je veux) et le fichier appConfig ne prend pas en compte ce changement ?

Merci