Encoding.ASCII it will throw this error=>{"There is no Unicode byte order mark. Cannot switch to Unicode."}
Solution:
public static T DeserializeObject(string xml)
{
using (TextReader reader = new StringReader(xml))
{
XmlSerializer xs = new XmlSerializer(typeof(T));
return (T)xs.Deserialize(reader);
}
}
Deserialize XML to object which has encoding ="utf-8"
public static T DeserializeObject(string xml)
{
XmlSerializer xs = new XmlSerializer(typeof(T));
MemoryStream memoryStream = new MemoryStream(StringToASCIIByteArray(xml));
XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.ASCII);
return (T)xs.Deserialize(memoryStream);
}
Thanks you - that solved a big headache I was having with this! :)
ReplyDeleteGlad it worked :)
Delete