We have some unit-tests that are checking UTF-8 byte marking of an XML string before it's loaded into an XmlDocument. Everything works fine using Windows 7 64-bit, but we noticed a bunch of tests failing while trying to run under Windows 10 64-bit.
After a bit of investigation, we found that the XML string on Windows 10 is getting pruned (the preamble exists), while on Windows 7 it does not.
Here is the code snippet:
public static string PruneUtf8ByteMark(string xmlString)
{
var byteOrderMarking = Encoding.UTF8.GetString(Encoding.UTF8.GetPreamble());
if (xmlString.StartsWith(byteOrderMarking))
{
xmlString = xmlString.Remove(0, byteOrderMarking.Length);
}
return xmlString;
}
StartsWith
is returning true for Windows 10, and false for Windows 7. Note that the same XML string is being used, the only difference here is the OS.
Any ideas? We are a bit lost here, since both PCs are x64 running the same .NET version.
edit: The string comes from a class via:
public static string XmlString = "<?xml version=\"1.0\"....
On Windows 10, the less than sign gets truncated because the byte mark check is true.