lvgamedev / simairport-modding

4 stars 4 forks source link

i18n doesn't load correctly if XML file has XML Declaration set as UTF-16 #132

Open NALStudio opened 4 years ago

NALStudio commented 4 years ago

If you have a XML Declaration with utf-16 as encoding it will not load the i18n properly with the following error:

[Sorry, this was the wrong error] (And no this is not the error code.)
System.Xml.XmlException: There is no Unicode byte order mark. Cannot switch to Unicode.
  at System.Xml.XmlTextReaderImpl.Throw (System.Exception e) [0x00027] in <1d98d70bb7d8453b80c25aa561fdecd1>:0 
  at System.Xml.XmlTextReaderImpl.ThrowWithoutLineInfo (System.String res) [0x00017] in <1d98d70bb7d8453b80c25aa561fdecd1>:0 
  at System.Xml.XmlTextReaderImpl.CheckEncoding (System.String newEncodingName) [0x000ad] in <1d98d70bb7d8453b80c25aa561fdecd1>:0 
  at System.Xml.XmlTextReaderImpl.ParseXmlDeclaration (System.Boolean isTextDecl) [0x0065c] in <1d98d70bb7d8453b80c25aa561fdecd1>:0 
  at System.Xml.XmlTextReaderImpl.Read () [0x000c6] in <1d98d70bb7d8453b80c25aa561fdecd1>:0 
  at System.Xml.XmlReader.MoveToContent () [0x0003a] in <1d98d70bb7d8453b80c25aa561fdecd1>:0 
  at System.Xml.Linq.XElement.Load (System.Xml.XmlReader reader, System.Xml.Linq.LoadOptions options) [0x0000e] in <a9ef27d60e3144519c0741b6584ba229>:0 
  at System.Xml.Linq.XElement.Load (System.String uri, System.Xml.Linq.LoadOptions options) [0x0000f] in <a9ef27d60e3144519c0741b6584ba229>:0 
  at System.Xml.Linq.XElement.Load (System.String uri) [0x00000] in <a9ef27d60e3144519c0741b6584ba229>:0 
  at i18n.loadLocaleFromDisk (System.String locale, System.Collections.Generic.Dictionary`2[System.String,System.String]& index) [0x0002c] in <70bde3e437ea4c60a6ef6f742a8b4c1b>:0 

and:

[0]: Could not laod i18n at path "C:/Users/[USER]/AppData/LocalLow/LVGameDev LLC/SimAirport\Mods\This should break it\i18n\en.xml"; 

(Also that laod is not my typo it is inside the game code)

This is most likely because i18n loadLocaleFromDisk loads the XML through XElement (Which doesn't take XML Declarations into consideration) and not XDocument (Which does (at least through my testing) take XML Declarations into consideration)

You can reproduce it with the mod attached. You can change it to utf-8 or remove it and it will work correctly. This should break it.zip