Moin,
ich probiere ein wenig rum und komm leider Gottes an einer Stelle nicht weiter, Google hat jetzt nicht wirklich geholfen eventuell hat jemand eine Lösung parat.
Bash
System.InvalidProgramException: Invalid IL code in System.Configuration.ConfigurationManager:get_AppSettings (): method body is empty.
at Programm.CFGManager.GetConfig (System.String key) [0x00001] in <a1705763910a4206b961b8c569bbe24c>:0
at Programm.Form1.Form1_Load (System.Object sender, System.EventArgs e) [0x0000e] in <a1705763910a4206b961b8c569bbe24c>:0
at System.Windows.Forms.Form.OnLoad (System.EventArgs e) [0x00022] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
at System.Windows.Forms.Form.OnLoadInternal (System.EventArgs e) [0x00029] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
C
public static void SetConfig(string key, string value)
{
var configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
var settings = configFile.AppSettings.Settings;
if (settings[key] == null)
{
settings.Add(key, value);
}
else
{
settings[key].Value = value;
}
configFile.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection(configFile.AppSettings.SectionInformation.Name);
}
public static void SetConfigInt(string key, int value)
{
var configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
var settings = configFile.AppSettings.Settings;
if (settings[key] == null)
{
settings.Add(key, Convert.ToString(value));
}
else
{
settings[key].Value = Convert.ToString(value);
}
configFile.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection(configFile.AppSettings.SectionInformation.Name);
}
/// <summary>
/// Get key value, if not found, return null
/// </summary>
/// <param name="key"></param>
/// <returns>null if key is not found, else string with value</returns>
public static string GetConfig(string key)
{
return ConfigurationManager.AppSettings[key];
}
Alles anzeigen
Gruß