E
Einar Høst
Hi,
I'm having weird problems using StringWriter and XmlTextWriter. My code
looks like this:
StringWriter sw = new StringWriter(CultureInfo.InvariantInfo);
XmlTextWriter xtw = new XmlTextWriter(sw); // NullReferenceException
thrown here!
xtw.WriteStartDocument();
xtw.WriteStartElement("MyRoot");
/// Write some nodes.
xtw.WriteEndElement(); // MyRoot
xtw.WriteEndDocument();
xtw.Close();
string str = sw.ToString();
It's been working swell until now, and it still works from a test app I'm
using. However, when interacting with the real app we're developing, the
code now crashes at the second line - apparently XmlTextWriter's constructor
isn't too happy about the input its getting?
Hope someone can shed a bit of light on this - it's mighty dim at best to
me.
Note btw that everything works well if I omit the XmlTextWriter and write
everything to the StringWriter...
Kind regards,
Einar.
I'm having weird problems using StringWriter and XmlTextWriter. My code
looks like this:
StringWriter sw = new StringWriter(CultureInfo.InvariantInfo);
XmlTextWriter xtw = new XmlTextWriter(sw); // NullReferenceException
thrown here!
xtw.WriteStartDocument();
xtw.WriteStartElement("MyRoot");
/// Write some nodes.
xtw.WriteEndElement(); // MyRoot
xtw.WriteEndDocument();
xtw.Close();
string str = sw.ToString();
It's been working swell until now, and it still works from a test app I'm
using. However, when interacting with the real app we're developing, the
code now crashes at the second line - apparently XmlTextWriter's constructor
isn't too happy about the input its getting?
Hope someone can shed a bit of light on this - it's mighty dim at best to
me.
Note btw that everything works well if I omit the XmlTextWriter and write
everything to the StringWriter...
Kind regards,
Einar.