I am attempting to modify a utf-16 encoded XML file in C# (specifically Unity 2017.4.33f1).
EDIT: Turns out the original file specified a utf-8 encoding!
I am loading the document using this code:
using (FileStream fileStream = new FileStream(inPath, FileMode.Open, FileAccess.Read))
{
_Document = XDocument.Load(fileStream);
}
When inspecting the object from a debugger, the XDocument seems to have loaded the declaration of the document as UTF-8, even though the original document specifies UTF-16.
Why is this happening? Is there any way to stop the XDocument from changing the encoding when loading a file?