Category: xml

WriteStartDocument() throws InvalidOperationException

I’m trying to generate XML and I encounter this exception: XmlTextWriter xmlWriter = new XmlTextWriter(Response.OutputStream, Encoding.UTF8); xmlWriter.WriteStartDocument(); xmlWriter.WriteStartElement(“userInfo”); It gives me an exception: WriteStartDocument needs to be the first call. But as you can see, I did call the WriteStartDocument() first! Any ideas?