I'm hoping someone can help me with this annoying little problem I'm having. I'm trying to write a file path to an XML settings file, but nothing happens. I don't get any error messages or Just in Time debugging windows, it just doesn't execute that code block.
The program feature is one where you setup user accounts, and select a file for each account. If I leave the file paths blank, the XML file is created with no problems. However, if there is even one path to be written the file never even gets created.
Here is a sample of my function:
private void SaveSettings()
{
XmlWriterSettings xml_settings = new XmlWriterSettings();
xml_settings.Indent = true;
xml_settings.IndentChars = (" ");
using (XmlWriter xml_settings_file = XmlWriter.Create("settings.xml", xml_settings))
{
xml_settings_file.WriteStartElement("Main_Node");
xml_settings_file.WriteElementString("SettingA", Properties.Settings.Default.SettingA.ToString());
xml_settings_file.WriteElementString("SettingB", Properties.Settings.Default.SettingB.ToString());
xml_settings_file.WriteElementString("SettingC", Properties.Settings.Default.SettingC.ToString());
for (int i = 1; i < Properties.Settings.Default.UserAccounts.Count; i++)
{
xml_settings_file.WriteElementString("Account", System.Security.SecurityElement.Escape(Properties.Settings.Default.UserAccounts[i].ToString()));
xml_settings_file.WriteElementString("File", System.Security.SecurityElement.Escape(Properties.Settings.Default.FilePaths[i]));
}
xml_settings_file.WriteEndElement();
xml_settings_file.Flush();
}
}
To make things more confusing, when I replace the FilePath variable with a simple "Test" string, it works fine and the file is created with no problems.
This has yet to be solved. I ended up just using the built-in application settings instead.