What could cause an XML file to be filled with null characters?

前端 未结 5 1493
忘掉有多难
忘掉有多难 2020-12-28 18:01

This is a tricky question. I suspect it will require some advanced knowledge of file systems to answer.

I have a WPF application, \"App1,\" targeting .NET framework

5条回答
  •  天涯浪人
    2020-12-28 18:31

    I have the same problem, there is an extra "NUL" character at the end of serialized xml file:

    I am using XMLWriter like this:

    using (var stringWriter = new Utf8StringWriter())
            {
                using (var xmlWriter = XmlWriter.Create(stringWriter, new XmlWriterSettings { Indent = true, IndentChars = "\t", NewLineChars = "\r\n", NewLineHandling = NewLineHandling.Replace }))
                {                    
                    xmlSerializer.Serialize(xmlWriter, data, nameSpaces);
                    xml =  stringWriter.ToString();
                    var xmlDocument = new XmlDocument();
                    xmlDocument.LoadXml(xml);
                    if (removeEmptyNodes)
                    {
                        RemoveEmptyNodes(xmlDocument);
                    }
                    xml = xmlDocument.InnerXml;
                }
            }
    

提交回复
热议问题