I can reproduce my problem using this straightforward C# console application code:
static void Main( string[] args ) { StringBuilder xmlsb = new StringBuilder(); using ( XmlWriter xw = XmlWriter.Create( xmlsb ) ) { xw.WriteStartDocument( true ); xw.WriteStartElement( "MyDocument" ); for ( int fi = 0; fi < 50; ++fi ) { xw.WriteStartElement( "item" ); for ( int indx = 10; indx < 55; ++indx ) { string attrName = "Attribute.Name." + indx; string attrValue = "dummy123456789"; xw.WriteAttributeString( attrName, attrValue ); } xw.WriteEndElement(); } xw.WriteEndElement(); xw.WriteEndDocument(); } string strXML = xmlsb.ToString(); strXML = strXML; }
The values are chosen to make it easier for demonstration purposes to spot the corruption in the resultant xml.
I've only seen any corruption when there's quite a bit of output - those values and strings seem to reproduce it for me.
To test this yourself, put a breakpoint on the strXML = strXML line and run the program.
When it breaks, examine the string in the debugger text visualizer, copy the entire string to the clipboard and paste it into a blank XML document in VS (have VS set to format the XML to put each attribute on a separate line), then scroll down the document and look for anywhere the otherwise tidy alignment goes awry.
I inevitably see something like this around half way through the XML:
Attribute.Name.21="dummy123456789" Attribute.Name.22="dummy123456789" Attribute.Name.23="dummy...y123456789" Attribute.Name.40="dummy123456789" Attribute.Name.41="dummy123456789"
The corruption can be in the attribute or value.
Have I got something wrong in my code that I just can't spot?