From 7e5a90ba87857eba9e7c59c8b07d466edc9524da Mon Sep 17 00:00:00 2001 From: Robert Paciorek Date: Tue, 9 Jan 2024 16:08:42 +0000 Subject: [PATCH] use utf-8 in xml headers from SerializeXml we use ascii/utf-8 (not utf-16) encoding in files and network data so XML header should be always `` --- src/Util/XmlUtil.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Util/XmlUtil.cs b/src/Util/XmlUtil.cs index ec31f93..aaaaa2e 100644 --- a/src/Util/XmlUtil.cs +++ b/src/Util/XmlUtil.cs @@ -1,5 +1,6 @@ using System.Reflection; using System.Xml.Serialization; +using System.Text; namespace sodoff.Util; public class XmlUtil { @@ -9,9 +10,13 @@ public class XmlUtil { return (T)serializer.Deserialize(reader); } + private class Utf8StringWriter : StringWriter { + public override Encoding Encoding => Encoding.UTF8; + } + public static string SerializeXml(T xmlObject) { var serializer = new XmlSerializer(typeof(T)); - using (var writer = new StringWriter()) { + using (var writer = new Utf8StringWriter()) { serializer.Serialize(writer, xmlObject); return writer.ToString(); }