Search Unity

XML filestream and encoding

Discussion in 'Scripting' started by munkbusiness, Jul 8, 2019.

  1. munkbusiness

    munkbusiness

    Joined:
    Aug 22, 2017
    Posts:
    46
    Hey I have a localization system in my game that loads in xml files to change all text.

    This system has been working fine with latin letters and Cyrillic also. I just added simplified chinese and it worked perfectly fine in the editor. However in my build, when i try to load i get this error:

    Code (CSharp):
    1. NotSupportedException: Encoding 936 data could not be found. Make sure you have correct international codeset assembly installed and enabled.
    2.   at System.Text.Encoding.GetEncoding (System.Int32 codepage) [0x0023f] in <0000d56de0ae43ca875d7babfd990580>:0
    3.   at System.Text.Encoding.GetEncoding (System.String name) [0x00012] in <0000d56de0ae43ca875d7babfd990580>:0
    4.   at System.Xml.XmlTextReaderImpl.CheckEncoding (System.String newEncodingName) [0x000df] in <fe0e6f140c4b48d8aa1157e558e9e215>:0
    5. Rethrow as XmlException: System does not support 'GB2312' encoding. Line 1, position 31.
    This is my XML loading code:

    Code (CSharp):
    1. XmlSerializer serializer = new XmlSerializer(typeof(LocalizationData));
    2.  
    3.             FileStream stream = new FileStream(dataPath + path + language + ext, FileMode.Open);
    4.             data = serializer.Deserialize(stream) as LocalizationData;
    5.             stream.Close();
    The xml document itself has encoding="GB2312" and validates fine itself.

    Can I make the serializer use the encoding of the XML file? Or can I make some kind of list of which encodings should be support?