[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework

serialization & SerializableAttribute

Ashutosh

10/15/2008 3:40:00 PM

Hi,
Can someone please tell me whats so special in applying the
"Serializable" attribute to a type??? I understand that it must be
applied to a type if it has to be serialized. I want know what extra
work the compiler does in this case?

I know how to crate attributes and how a method/type can check for the
presence of a attribute and also that this is a Pseudo-custom
attribute....When any attribute is applied to a type, the compiler just
adds the information to the meta data of the module, which can be
retrieved at the run time.

*So, does the compiler does some check on the type or restrict the
declaration of a type when Serializable attribute is applied to it?*

Thanks & Regards,
Ashutosh
2 Answers

stcheng

10/16/2008 3:12:00 AM

0

Hi Ashutosh,

As for the "SerializableAttribute", it is the same as other .NET Attributes
which decorate the certain class or class member (SerializableAttribute is
for class level). And the compiler will just emit some info in metadata of
the certain class to indicate that the class has marked with serializable.

About "how this attribute will work at runtime", here is the case when it
will perform important roles:

**Whenever you try persist a class instance into some storage which need to
ensure the class is serializable(the serialize here is binary serialize),
such as SQL Server session state, ASP.NET ViewState, , the runtime will try
inspecting the metadata of that class to see whether it has been marked
with this attribute. If so, that instance will be serialized(by the .NET
runtime's default object serializer) and stored into the target storage.
Otherwise, exception will be thrown.

**Or if you explicitly use BinarySerializer to serialize a class instance,
the runtime will also perform such check to ensure the class is
serialize(either marked with this attribute or has explicitly implement
the ISerializable interface).


Also, from the "how the binary serialization is implemented" perspective,
using "SerializableAttribute" means you let the .NET runtime help you
generate the object serializing rule and logic automatically. While if you
manually implement "ISerializable" interface, you will need to add the code
logic for serializing the certain class's instances.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#not....

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://support.microsoft.com/select/default.aspx?target=assistance&am....
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.



--------------------
>Date: Wed, 15 Oct 2008 21:10:01 +0530
>From: Ashutosh <smbs-msdn@nospam.nospam>
>User-Agent: Thunderbird 2.0.0.17 (Windows/20080914)
>MIME-Version: 1.0
>Subject: serialization & SerializableAttribute
>
>Hi,
>Can someone please tell me whats so special in applying the
>"Serializable" attribute to a type??? I understand that it must be
>applied to a type if it has to be serialized. I want know what extra
>work the compiler does in this case?
>
>I know how to crate attributes and how a method/type can check for the
>presence of a attribute and also that this is a Pseudo-custom
>attribute....When any attribute is applied to a type, the compiler just
>adds the information to the meta data of the module, which can be
>retrieved at the run time.
>
>*So, does the compiler does some check on the type or restrict the
>declaration of a type when Serializable attribute is applied to it?*
>
>Thanks & Regards,
>Ashutosh
>
>

stcheng

10/20/2008 10:55:00 AM

0

Hi Ashutosh,

Have you got any progress on this issue or does the information in my last
reply help you some?

If you still have any questions or anything else need help, please feel
free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.


--------------------
>From: stcheng@online.microsoft.com ("Steven Cheng")
>Organization: Microsoft
>Date: Thu, 16 Oct 2008 03:12:26 GMT
>Subject: RE: serialization & SerializableAttribute

>Hi Ashutosh,
>
>As for the "SerializableAttribute", it is the same as other .NET
Attributes
>which decorate the certain class or class member (SerializableAttribute is
>for class level). And the compiler will just emit some info in metadata of
>the certain class to indicate that the class has marked with serializable.

>
>About "how this attribute will work at runtime", here is the case when it
>will perform important roles:
>
>**Whenever you try persist a class instance into some storage which need
to
>ensure the class is serializable(the serialize here is binary serialize),
>such as SQL Server session state, ASP.NET ViewState, , the runtime will
try
>inspecting the metadata of that class to see whether it has been marked
>with this attribute. If so, that instance will be serialized(by the .NET
>runtime's default object serializer) and stored into the target storage.
>Otherwise, exception will be thrown.
>
>**Or if you explicitly use BinarySerializer to serialize a class instance,
>the runtime will also perform such check to ensure the class is
>serialize(either marked with this attribute or has explicitly implement
>the ISerializable interface).
>
>
>Also, from the "how the binary serialization is implemented" perspective,
>using "SerializableAttribute" means you let the .NET runtime help you
>generate the object serializing rule and logic automatically. While if you
>manually implement "ISerializable" interface, you will need to add the
code
>logic for serializing the certain class's instances.
>
>Sincerely,
>
>Steven Cheng
>
>Microsoft MSDN Online Support Lead
>
>
>Delighting our customers is our #1 priority. We welcome your comments and
>suggestions about how we can improve the support we provide to you. Please
>feel free to let my manager know what you think of the level of service
>provided. You can send feedback directly to my manager at:
>msdnmg@microsoft.com.
>
>==================================================
>Get notification to my posts through email? Please refer to
>http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#not....
>
>Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
>where an initial response from the community or a Microsoft Support
>Engineer within 1 business day is acceptable. Please note that each follow
>up response may take approximately 2 business days as the support
>professional working with you may need further investigation to reach the
>most efficient resolution. The offering is not appropriate for situations
>that require urgent, real-time or phone-based interactions or complex
>project analysis and dump analysis issues. Issues of this nature are best
>handled working with a dedicated Microsoft Support Engineer by contacting
>Microsoft Customer Support Services (CSS) at
>http://support.microsoft.com/select/default.aspx?target=assistance&am...