On Mono, XmlSerializer.Serialize(object, stream) uses the default encoding for 
the platform. .NET appears not to specify an encoding, as evidenced by the 
output from the code below.

Due to the way it currently works on Mono, Unicode characters don't get 
serialized and deserialized on Mono correctly when using the 
XmlSerializer.Serialize(object, stream) constructor:

Here's the example code:

Attachment: XmlSerializationText.cs
Description: XmlSerializationText.cs


Here's the output: 

Mono: (tested on r147679, but XmlSerializer.cs has no changes in HEAD)
 <?xml version="1.0" encoding="utf-8"?><Foo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><Bar>Biz</Bar></Foo>

.NET 3.5
<?xml version="1.0"?><Foo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><Bar>Biz</Bar></Foo>


Here's a patch that makes Mono do what .NET does in this case.

Index: mcs/class/System.XML/System.Xml.Serialization/XmlSerializer.cs
===================================================================
--- mcs/class/System.XML/System.Xml.Serialization/XmlSerializer.cs      
(revision 147679)
+++ mcs/class/System.XML/System.Xml.Serialization/XmlSerializer.cs      
(working copy)
@@ -413,7 +413,7 @@
 
                public void Serialize (Stream stream, object o)
                {
-                       XmlTextWriter xmlWriter = new XmlTextWriter (stream, 
System.Text.Encoding.Default);
+                       XmlTextWriter xmlWriter = new XmlTextWriter (stream, 
null);
                        xmlWriter.Formatting = Formatting.Indented;
                        Serialize (xmlWriter, o, null);
                }
@@ -432,7 +432,7 @@
 
                public void Serialize (Stream stream, object o, 
XmlSerializerNamespaces namespaces)
                {
-                       XmlTextWriter xmlWriter = new XmlTextWriter (stream, 
System.Text.Encoding.Default);
+                       XmlTextWriter xmlWriter = new XmlTextWriter (stream, 
null);
                        xmlWriter.Formatting = Formatting.Indented;
                        Serialize (xmlWriter, o, namespaces);
                }
_______________________________________________
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list

Reply via email to