[Mono-devel-list] Deserialization (reflection) bug
Lluis Sanchez
lluis at ideary.com
Wed Jul 2 17:19:34 EDT 2003
Fixed in CVS. Your app is really good finding serialization bugs :-)
----- Original Message -----
From: "Herscovici, Avi" <AHerscovici at Empirix.com>
To: <mono-devel-list at lists.ximian.com>
Sent: Wednesday, July 02, 2003 6:52 PM
Subject: [Mono-devel-list] Deserialization (reflection) bug
> Hi guys + lluis,
>
> Got a new deserialization bug. I've pasted code. Problem goes away
when
> I get rid of the second Add method in obj1 class. Seems like reflection
> doesn't like overloaded methods? May also have to do with implementing
> CollectionBase. I think I've had the exact same problem that came from
the
> XmlSerializer constructor (that Lluis fixed) with an example that
> implemented collectionbase, but now it is coming from deserialize. Either
> way here are the files and the error:
>
>
> // --------------test.cs---------------
> using System;
> using System.Xml.Serialization;
> using System.IO;
> using System.Xml;
> using Test;
>
>
> namespace Serial.test {
>
> public class sertest {
>
> public static void Save(System.IO.Stream stream, object x)
> {
> XmlSerializer ser = new XmlSerializer(typeof(obj1));
> ser.Serialize(stream, x);
> }
>
> public static void Save(string filename, object x)
> {
> FileStream str = new FileStream(filename,
> FileMode.Create, FileAccess.Write);
> Save(str, x);
> str.Close();
> }
>
> public static object Load(System.IO.Stream stream)
> {
> object s;
> Console.WriteLine("Debug line 1a");
> XmlSerializer ser = new XmlSerializer(typeof(obj1));
> Console.WriteLine("Debug line 2a");
> s = (object)ser.Deserialize(stream);
> return s;
> }
>
>
> public static object Load(string filename)
> {
> object s;
> Console.WriteLine("Debug line 2");
> FileStream str = new FileStream(filename,
> FileMode.Open, FileAccess.Read);
> Console.WriteLine("Debug line 3");
> s = Load(str);
> Console.WriteLine("Debug line 4");
> str.Close();
> return s;
> }
>
> static void Main() {
> string filename = "st4.ser";
> obj1 x = new obj1();
> x.Add(new obj2());
> Save(filename, x);
> obj1 temp = (obj1)Load(filename);
> Console.WriteLine("Finished");
> }
> }
> }
>
> // ----------------- obj1.cs -------------
> using System;
> using System.Collections;
> using System.Diagnostics;
>
> namespace Test
> {
> public sealed class obj1 : CollectionBase
> {
> public void Add(obj2 sllp)
> {
> InnerList.Add(sllp);
> }
>
> public void Add(object name, object val)
> {
> InnerList.Add(new obj2(name, val));
> }
>
> public void Remove(obj2 sllp)
> {
> InnerList.Remove(sllp);
> }
>
> public obj2 this[int index]
> {
> [DebuggerStepThrough]
> get { return (obj2)InnerList[index]; }
> [DebuggerStepThrough]
> set { InnerList[index] = value; }
> }
> }
> }
> // ---------------obj2.cs------------------
> using System;
> using System.Diagnostics;
> using System.Collections;
>
> namespace Test
> {
> public class obj2
> {
> private object m_name = null;
> private object m_value = null;
>
> public obj2()
> {
> }
>
> public obj2(object name, object val)
> {
> m_name = name;
> m_value = val;
> }
>
> public object Name
> {
> [DebuggerStepThrough]
> get { return m_name; }
> [DebuggerStepThrough]
> set { m_name = value; }
> }
>
> public object Value
> {
> [DebuggerStepThrough]
> get { return m_value; }
> [DebuggerStepThrough]
> set { m_value = value; }
> }
>
> }
> }
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>
More information about the Mono-devel-list
mailing list