I have following problem:
When I run the executable of my WinForms application (under Release or Debug - WindowsFormsApplication.exe) it works fine. Now I can choose a save file (a text file) for loading settings in the program or enter them my own and save them into a file. The path to the file is written into my appconfig (WindowsFormsApplication.EXE.config)
Configuration config = ConfigurationManager.OpenExeConfiguration
(System.Windows.Forms.Application.ExecutablePath);
config.AppSettings.Settings.Remove("Path");
config.AppSettings.Settings.Add("Path", openFile.FileName);
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");
savePath = ConfigurationManager.AppSettings["Path"];
When I start the application the next time it should read the path via
savePath = ConfigurationManager.AppSettings["Path"];
if (savePath != "" || savePath != String.Empty)
saveFile.LoadUserSettings();
There in LoadUserSettings it starts reading the file:
if (File.Exists(form1.savePath))
{
using (StreamReader reader = new StreamReader(form1.savePath))
{
reader.ReadLine();
//reading text file
}
}
However, the application crashes immediately and can not be started anymore. If I delete path from the appconfig it works again. Does someone know what happens here? In Visual Studio this works fine.