XML Serialization - Why can't I change the encoding?

y0uclose

New Member
This should hopefully be a simple one.I am serializaing a List<> of C# objects to an XML document. Everything is going great however my XML document has ASCII encoding (spaces are represented as \[code\]X0020\[/code\] for example) and the client is complaining so I want to change the encoding to UTF8 like so:\[code\]private void SerializeToXML(List<ResponseData> finalXML){ XmlSerializer serializer = new XmlSerializer(typeof(List<ResponseData>)); TextWriter textWriter = new StreamWriter(txtFileLocation.Text, Encoding.UTF8); serializer.Serialize(textWriter, finalXML); textWriter.Close();}\[/code\]Intellisense is telling me this should work...
Cdnrc.jpg
...but is complaining when I try it...
QNktA.jpg
What am I doing wrong?Thanks
 
Back
Top