I am trying to serialize text to xml file that contains of german ä character, when I run this code on one PC it works fine, on other PC instead of ä I am getting д or д, on other PC when I run code I am getting square. I tried different things, here is my code:
string text = "säure";
XmlSerializerNamespaces xmlnsEmpty = new XmlSerializerNamespaces();
xmlnsEmpty.Add("", ""); // This line solves the issue with saving XML file with German letters on some PCs
XmlSerializer xmlSerializer = new XmlSerializer(typeof(string));
var utfWithoutBom = new UTF8Encoding(false);
var settings = new XmlWriterSettings
{
Encoding = Encoding.UTF8, // Use UTF-8 to support German letters
Indent = true,
OmitXmlDeclaration = true,
};
using var stream = new FileStream("output.xml", FileMode.Create);
//using var sw = new StreamWriter(stream,Encoding.GetEncoding("ISO-8859-1"));
using var writer = XmlWriter.Create(stream, settings);
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("de-DE");
xmlSerializer.Serialize(writer, text, xmlnsEmpty);
For example I am getting this result:
As you can see from my code I tried almost everything, but notihng helps. What I am doing wrong?
