[Mono-devel-list] XmlSerializer

psonek2 psonek2 at seznam.cz
Tue Jul 13 02:47:39 EDT 2004


Done, http://bugzilla.ximian.com/show_bug.cgi?id=61464

I set low priority, it's not bug actualy, just different behaviour.

Btw serialization works perfectly for me, thanks
Radek

-----Original Message-----
From: mono-devel-list-admin at lists.ximian.com
[mailto:mono-devel-list-admin at lists.ximian.com] On Behalf Of Lluis Sanchez
Sent: Monday, July 12, 2004 9:18 AM
To: radek polak
Cc: mono-devel-list at lists.ximian.com
Subject: Re: [Mono-devel-list] XmlSerializer

Can you file a bug report in bugzilla.ximian.com with this info?
Thanks!

On ds, 2004-07-10 at 23:45, radek polak wrote:
> Hello,
> this code works under MS.NET, but throws following exception on mono
beta3:
> 
> System.InvalidOperationException: SerializationTest.MyList cannot be
serialized because it does not have a default public constructor
> 
> Exception under Mono seems logical to me. I am trying to serialize MyList
class, that has no public constructor. But how is it possible to work under
MS.NET? The reason must be, that MyList inherits from ArrayList.
> 
> Any ideas? Thanks. Radek.
> 
> using System;
> using System.IO;
> using System.Collections;
> using System.Xml.Serialization;
> 
> namespace SerializationTest
> {
> 	[Serializable]
> 	public class MyList : ArrayList
> 	{
> 		Container container;	// in real implementation i need to
know "my container"
> 
> 		// NOTE: MyList has no public constructor
> 		public MyList(Container container) : base() {
> 			this.container = container;
> 		}
> 	}
> 
> 	[Serializable]
> 	public class Container
> 	{
> 		public MyList Items;
> 
> 		public Container() {
> 			Items = new MyList(this);
> 		}
> 
> 		public void Save(Stream s) {
> 			XmlSerializer serializer = new
XmlSerializer(this.GetType());
> 			serializer.Serialize(s, this);
> 		}
> 
> 		public static Container FromStream(Stream s) {
> 			XmlSerializer serializer = new
XmlSerializer(typeof(Container));
> 			Container c = (Container) serializer.Deserialize(s);
> 			return c;
> 		}
> 
> 		public static void Main()
> 		{
> 			Container c = new Container();
> 			c.Items.Add(1);
> 			using(FileStream fs = new
FileStream("container.xml", FileMode.Create)) {
> 				c.Save(fs);
> 			}
> 
> 			Container fromFile =
Container.FromStream(File.OpenRead("container.xml"));
> 			Console.WriteLine("It works, first item is " +
fromFile.Items[0]);
> 			Console.ReadLine();
> 		}
> 	}
> }
> ____________________________________________________________
> Příjemný design. Příjemnější cena. SONY ERICSSON T105 již od 577 Kč
> http://ad.seznam.cz/clickthru?spotId=75826

_______________________________________________
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