I am trying to build a console application, where the user can decide, wether to enable logging or not. For that I got a app.config file in XML format. The Code can succesfully read the current state, but when I am trying to override the "protocol" property, I get the given exception in Line 27
My protocol class:
using System; using System.Collections.Generic; using System.Text; using System.Configuration; using System.Collections.Specialized; namespace Bruch { class Protokoll { public Protokoll() { string protokollConfigStatus = ConfigurationManager.AppSettings.Get("protokoll"); if (protokollConfigStatus == "unknown") { SetzeEinstellung("protokoll", "test"); }; } public static void SetzeEinstellung(string key, string value) { Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); configuration.AppSettings.Settings[key].Value = value;****************configuration.Save(ConfigurationSaveMode.Full, true); //this line ConfigurationManager.RefreshSection("appSettings"); } } }
my config file:
<?xml version="1.0" encoding="utf-8" ?><configuration><appSettings><add key="protokoll" value="unknown" /></appSettings></configuration>
The error message:
>System.Configuration.ConfigurationErrorsException: "An error occurred executing the configuration >section handler for configProtectedData.">>inner exception:>ConfigurationErrorsException: Invalid key value.