[Mono-list] Bug in XmlSerializer and tiny bugfix

Elan Feingold efeingold@mn.rr.com
Thu, 20 Feb 2003 19:49:14 -0600


This is a multi-part message in MIME format.

------=_NextPart_000_0092_01C2D919.25E01F10
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: 7bit

Hi,

I'm not sure why, but XmlSerializer.Serialize(Stream stream, object o)
is broken and produces garbage. Attached is a file that demonstrates the
problem.

In contrast, using XmlSerializer.Serialize(TextWriter textWriter, object
o) works fine.

I poked around for a little bit, but failed to turn up anything obvious,
proving the fact that I'm a newbie to the project.

I did fix one bug to the Serializer for Enum types. I added the
following code to XmlSerializer.cs and verified that the output matched
the output under .NET.

Best regards,

-elan

*** 558,564 ****
                        }
                        else if (type.IsEnum)
                        {
!                               // FIXME
                        }
                        else
                        { //Complex Type
--- 558,564 ----
                        }
                        else if (type.IsEnum)
                        {
!                 writer.WriteString(GetXmlValue(value));
                        }
                        else
                        { //Complex Type

------=_NextPart_000_0092_01C2D919.25E01F10
Content-Type: text/plain;
	name="test.cs"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="test.cs"

using System;=0A=
using System.IO;=0A=
using System.Xml;=0A=
using System.Xml.Serialization;=0A=
using System.Text;=0A=
=0A=
// Items in the shopping list=0A=
public class Item =0A=
{=0A=
    public RequestType Type;=0A=
    public Guid RequestId;=0A=
    public bool KeepAlive;=0A=
    public string Trove;=0A=
    public string Data;=0A=
=0A=
    public enum RequestType { List, Get }=0A=
=0A=
    public Item() {}=0A=
    public Item(RequestType type,=0A=
                Guid        requestId,=0A=
                bool        keepAlive,=0A=
                string      trove,=0A=
                string      data) =0A=
    {=0A=
        Type =3D type;=0A=
        RequestId =3D requestId;=0A=
        KeepAlive =3D keepAlive;=0A=
        Trove =3D trove;=0A=
        Data =3D data;=0A=
    }=0A=
}=0A=
=0A=
public class MainClass=0A=
{=0A=
    static void Main ()=0A=
    {=0A=
        Item item =3D new Item(Item.RequestType.List, =0A=
                             Guid.NewGuid(), =0A=
                             true, =0A=
                             "Trove-1", =0A=
                             "blah");=0A=
        =0A=
        // Serialization=0A=
        XmlSerializer s =3D new XmlSerializer(typeof(Item));=0A=
        =0A=
        // This doesn't work!=0A=
        MemoryStream mem =3D new MemoryStream();=0A=
        s.Serialize(mem, item);=0A=
        Console.WriteLine("The data: {0}", =
Encoding.ASCII.GetString(mem.ToArray()));=0A=
=0A=
        // This works!=0A=
        StringWriter w =3D new StringWriter();=0A=
        s.Serialize(w, item);=0A=
        Console.WriteLine("The data: {0}", =
w.GetStringBuilder().ToString());=0A=
        =0A=
        // Deserialization -- NOT IMPLEMENTED.=0A=
        //Item newItem;=0A=
        //TextReader r =3D new StreamReader( "item.xml" );=0A=
        //newItem =3D (Item)s.Deserialize(r);=0A=
        //r.Close();=0A=
    }=0A=
}=0A=

------=_NextPart_000_0092_01C2D919.25E01F10--