C# LoadXml System.Xml.XmlException: Data at the root level is invalid. Line 1, position 1.

去掉BOM头

writer = new XmlTextWriter(stream, new UnicodeEncoding(false,false));

如果是UTF8

writer = new XmlTextWriter(stream, new UTF8Encoding(false));
原文地址:https://www.cnblogs.com/hofmann/p/11812960.html