So here is the code that throws the exception
#region Header
if (textBox2.Text != "")
{
try
{
xmlTW.WriteStartElement("Header");
xmlTW.WriteRaw(Environment.NewLine);
xmlTW.WriteString(textBox2.Text);
xmlTW.WriteRaw(Environment.NewLine);
xmlTW.WriteEndElement();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
#endregion
#region Body
if (textBox3.Text != "")
{
try
{
xmlTW.WriteStartElement("Rectangles");
xmlTW.WriteRaw(Environment.NewLine + textBox3.Text + Environment.NewLine);
xmlTW.WriteEndElement();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
#endregion
So, the problem is that the code will run smoothly only if one of the two textboxes is filled with data, if both of them contain text i get an invalid operation exception at WriteEndDocument();
I know it must be something simple, but i just can't figure it out :P . Any help is appreciated.
Thanks in advance.