зеркало из https://github.com/mono/mail-archives.git
139 строки
6.0 KiB
HTML
139 строки
6.0 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
|
||
<HTML>
|
||
<HEAD>
|
||
<TITLE> [Mono-list] Xml Deserialize + Constructor Needed
|
||
</TITLE>
|
||
<LINK REL="Index" HREF="index.html" >
|
||
<LINK REL="made" HREF="mailto:rafaelteixeirabr%40hotmail.com">
|
||
<META NAME="robots" CONTENT="index,nofollow">
|
||
|
||
<LINK REL="Previous" HREF="016396.html">
|
||
<LINK REL="Next" HREF="016426.html">
|
||
</HEAD>
|
||
<BODY BGCOLOR="#ffffff">
|
||
<H1>[Mono-list] Xml Deserialize + Constructor Needed
|
||
</H1>
|
||
<B>A Rafael D Teixeira
|
||
</B>
|
||
<A HREF="mailto:rafaelteixeirabr%40hotmail.com"
|
||
TITLE="[Mono-list] Xml Deserialize + Constructor Needed">rafaelteixeirabr@hotmail.com
|
||
</A><BR>
|
||
<I>Tue, 14 Oct 2003 12:18:12 -0200</I>
|
||
<P><UL>
|
||
<LI> Previous message: <A HREF="016396.html">[Mono-list] mono blogs
|
||
</A></li>
|
||
<LI> Next message: <A HREF="016426.html">[Mono-list] Can I use my application on LInux?
|
||
</A></li>
|
||
<LI> <B>Messages sorted by:</B>
|
||
<a href="date.html#16399">[ date ]</a>
|
||
<a href="thread.html#16399">[ thread ]</a>
|
||
<a href="subject.html#16399">[ subject ]</a>
|
||
<a href="author.html#16399">[ author ]</a>
|
||
</LI>
|
||
</UL>
|
||
<HR>
|
||
<!--beginarticle-->
|
||
<PRE>Well, it's a necessity for xml serialization (I learned it the hard way),
|
||
that you have an "Default Constructor", what means that you need a
|
||
parameterless constructor (besides your other constructors).
|
||
|
||
That is easy to understand why: when deserializing the xml, the deserializer
|
||
sees an element that maps to a class, it then needs to create an instance of
|
||
that class, an *empty* instance of the class, that later will be "fleshed"
|
||
with other elements and attributes values (that's is also why only public
|
||
fields/properties can be serialized, because the serializer/deserializer is
|
||
outside the class).
|
||
|
||
If you furnish only constructors with parameters, how is the serializer
|
||
going to find what values, should it be passing to your constructor?
|
||
|
||
Best regards,
|
||
|
||
Rafael Teixeira
|
||
Brazilian Polymath
|
||
Mono Hacker since 16 Jul 2001
|
||
English Blog: <A HREF="http://monoblog.blogspot.com/">http://monoblog.blogspot.com/</A>
|
||
Brazilian Portuguese Blog: <A HREF="http://monoblog.weblogger.terra.com.br/">http://monoblog.weblogger.terra.com.br/</A>
|
||
|
||
|
||
|
||
><i>From: Pablo Fischer <<A HREF="mailto:pablo@pablo.com.mx">pablo@pablo.com.mx</A>>
|
||
</I>><i>To: <A HREF="mailto:mono-list@lists.ximian.com">mono-list@lists.ximian.com</A>
|
||
</I>><i>Subject: [Mono-list] Xml Deserialize + Constructor Needed
|
||
</I>><i>Date: Mon, 13 Oct 2003 23:58:22 -0500
|
||
</I>><i>
|
||
</I>><i>Hi all!
|
||
</I>><i>
|
||
</I>><i>I created a file in XML with the help of XmlSerialization, how I want to
|
||
</I>><i>Deserialize it, I found in may sites (also in msdn) a simple way to do
|
||
</I>><i>this, so my method:
|
||
</I>><i>
|
||
</I>><i>private static void Desarmar() {
|
||
</I>><i> Accounts accs = new Accounts("test");
|
||
</I>><i> XmlSerialize mySerializer = new XmlSerializer(typeof(Accounts));
|
||
</I>><i> FileStream myFileStream = new FileStream(".mbloggyrc", FileMode.Open);
|
||
</I>><i> accs = (Accounts)mySerializer.Deserialize(myFileStream);
|
||
</I>><i>}
|
||
</I>><i>
|
||
</I>><i>It compiles ok, but when I run it I get:
|
||
</I>><i>
|
||
</I>><i>Unhandled Exception: System.MissingMethodException: Default constructor
|
||
</I>><i>not found
|
||
</I>><i>in <0x00144> System.Activator:CreateInstance (System.Type,bool)
|
||
</I>><i>in <0x00012> System.Activator:CreateInstance (System.Type)
|
||
</I>><i>in <0x001ab>
|
||
</I>><i>System.Xml.Serialization.XmlSerializationReaderInterpreter:ReadClassInstance
|
||
</I>><i>(System.Xml.Serialization.XmlTypeMapping,bool,bool)
|
||
</I>><i>in <0x00067>
|
||
</I>><i>System.Xml.Serialization.XmlSerializationReaderInterpreter:ReadObject
|
||
</I>><i>(System.Xml.Serialization.XmlTypeMapping,bool,bool)
|
||
</I>><i>in <0x000a2>
|
||
</I>><i>System.Xml.Serialization.XmlSerializationReaderInterpreter:ReadObject ()
|
||
</I>><i>in <0x00075> System.Xml.Serialization.XmlSerializer:Deserialize
|
||
</I>><i>(System.Xml.Serialization.XmlSerializationReader)
|
||
</I>><i>in <0x00068> System.Xml.Serialization.XmlSerializer:Deserialize
|
||
</I>><i>(System.Xml.XmlReader)
|
||
</I>><i>in <0x0003f> System.Xml.Serialization.XmlSerializer:Deserialize
|
||
</I>><i>(System.IO.Stream)
|
||
</I>><i>in <0x0009a> .testing:Desarmar ()
|
||
</I>><i>in <0x0012c> .testing:Main ()
|
||
</I>><i>
|
||
</I>><i>A Default Constructor.. for what? I have a Constructor for each
|
||
</I>><i>element..
|
||
</I>><i>
|
||
</I>><i>Thanks!
|
||
</I>><i>Pablo
|
||
</I>><i>--
|
||
</I>><i>Pablo Fischer Sandoval (pablo [arroba/at] pablo.com.mx)
|
||
</I>><i><A HREF="http://www.pablo.com.mx">http://www.pablo.com.mx</A>
|
||
</I>><i><A HREF="http://www.debianmexico.org">http://www.debianmexico.org</A>
|
||
</I>><i>GPG FingerTip: 3D49 4CB8 8951 F2CA 8131 AF7C D1B9 1FB9 6B11 810C
|
||
</I>><i>Firma URL: <A HREF="http://www.pablo.com.mx/firmagpg.txt">http://www.pablo.com.mx/firmagpg.txt</A>
|
||
</I>><i>
|
||
</I>><i>_______________________________________________
|
||
</I>><i>Mono-list maillist - <A HREF="mailto:Mono-list@lists.ximian.com">Mono-list@lists.ximian.com</A>
|
||
</I>><i><A HREF="http://lists.ximian.com/mailman/listinfo/mono-list">http://lists.ximian.com/mailman/listinfo/mono-list</A>
|
||
</I>
|
||
_________________________________________________________________
|
||
MSN Messenger: instale gr<67>tis e converse com seus amigos.
|
||
<A HREF="http://messenger.msn.com.br">http://messenger.msn.com.br</A>
|
||
|
||
|
||
</PRE>
|
||
<!--endarticle-->
|
||
<HR>
|
||
<P><UL>
|
||
<!--threads-->
|
||
<LI> Previous message: <A HREF="016396.html">[Mono-list] mono blogs
|
||
</A></li>
|
||
<LI> Next message: <A HREF="016426.html">[Mono-list] Can I use my application on LInux?
|
||
</A></li>
|
||
<LI> <B>Messages sorted by:</B>
|
||
<a href="date.html#16399">[ date ]</a>
|
||
<a href="thread.html#16399">[ thread ]</a>
|
||
<a href="subject.html#16399">[ subject ]</a>
|
||
<a href="author.html#16399">[ author ]</a>
|
||
</LI>
|
||
</UL>
|
||
</body></html>
|