From: Julie on
Hi everyone,
I've been looking over serialization and am slightly confused... Is the
SerializableAttribute required above the class when using XML serialization?

If not, why not? If so, why so?

Thanks in advance.

Example:
[Serializable()] // REQUIRED??!?!
public class Group
{
[XmlAttribute ()]
public string GroupName;

[XmlAttribute()]
public Byte [] GroupNumber;

[XmlAttribute()]
public DateTime Today;
}

From: Alberto Poblacion on
"Julie" <julie(a)home.com> wrote in message
news:OarIT6W3KHA.1016(a)TK2MSFTNGP02.phx.gbl...
> I've been looking over serialization and am slightly confused... Is the
> SerializableAttribute required above the class when using XML
> serialization?

No. Only runtime serialization (binary or SOAP) requires the
SerializableAttribute. The XmlSerializer does not need it.

> If not, why not? If so, why so?

The immediate reason is that when runtime serialization performs
reflection on the serialized object to extract it members, it first checks
to see if the attribute is present, and otherwise refuses to proceed. The
XmlSerializer does not perform any such checks. However, this leads us to
question why the designers of the Framework class libraries decided to make
things in that way. I am not aware of any document explainig the reasoning
that led to this design.

From: Tony Johansson on
"Julie" <julie(a)home.com> skrev i meddelandet
news:OarIT6W3KHA.1016(a)TK2MSFTNGP02.phx.gbl...
> Hi everyone,
> I've been looking over serialization and am slightly confused... Is the
> SerializableAttribute required above the class when using XML
> serialization?
>
> If not, why not? If so, why so?
>
> Thanks in advance.
>
> Example:
> [Serializable()] // REQUIRED??!?!
> public class Group
> {
> [XmlAttribute ()]
> public string GroupName;
>
> [XmlAttribute()]
> public Byte [] GroupNumber;
>
> [XmlAttribute()]
> public DateTime Today;
> }

If you will use XML Serialization you must perform the following task.
1.Specify the class as public
2.Specify all members that must be serialized as public
3.Create a parameterless c-tor. Often called default c-tor

Note as you mentioned unlike classes processed with standard serialization,
classes do not have to have the serialization attribute to be processed with
the XML serialization, If there are private or protected members, they will
be skipped during serialization.

If you want to know why you don't have to specify serialization attribute
you have to ask the person who created .NET!

//Tony


From: Mr. Arnold on
Julie wrote:
> Hi everyone,
> I've been looking over serialization and am slightly confused... Is the
> SerializableAttribute required above the class when using XML
> serialization?
>
> If not, why not? If so, why so?
>
> Thanks in advance.
>
> Example:
> [Serializable()] // REQUIRED??!?!
> public class Group
> {
> [XmlAttribute ()]
> public string GroupName;
>
> [XmlAttribute()]
> public Byte [] GroupNumber;
>
> [XmlAttribute()]
> public DateTime Today;
> }

The attribute is required if you want to XML serialize the class/object.
I don't know what the XMLAttribute is about. I don't think you need it.

Where is the get/set for each one of the public properties? Maybe I am
missing something here, but you do need to get data from the property
and set data in the property with backing private variables in the class
for the public properties.

Or you can use auto-property.



From: Julie on
Thank you so much! Exactly the answer i wanted :-)


"Alberto Poblacion" <earthling-quitaestoparacontestar(a)poblacion.org> wrote
in message news:ee0OEEX3KHA.3580(a)TK2MSFTNGP05.phx.gbl...
> "Julie" <julie(a)home.com> wrote in message
> news:OarIT6W3KHA.1016(a)TK2MSFTNGP02.phx.gbl...
>> I've been looking over serialization and am slightly confused... Is the
>> SerializableAttribute required above the class when using XML
>> serialization?
>
> No. Only runtime serialization (binary or SOAP) requires the
> SerializableAttribute. The XmlSerializer does not need it.
>
>> If not, why not? If so, why so?
>
> The immediate reason is that when runtime serialization performs
> reflection on the serialized object to extract it members, it first checks
> to see if the attribute is present, and otherwise refuses to proceed. The
> XmlSerializer does not perform any such checks. However, this leads us to
> question why the designers of the Framework class libraries decided to
> make things in that way. I am not aware of any document explainig the
> reasoning that led to this design.
>