Question about SQL Session Management ASP.NET and How to serialise Object

E

Evian Spring

We are planning on using "SqlServer" mode for our ASP.NET session
state.

I know for the classes we store in Session that I need to mark them
with the SerializableAttribute as described in this knowledge base
article:

http://support.microsoft.com/default.aspx?scid=KB;EN-US;q312112&ID=KB;EN-US;q312112

My question is, if I store in session a class that contains members
that are classes and so on, will marking my class with the
SerializableAttribute the only thing I need?


I have written a simple class shown below.....will marking
MyClassExample with SerializableAttribute the only thing I need? I
think the member variable that are not object will serialize no problem
but I not sure for Class1 in my exmaple below...........I know I may
need to implement the ISerializable interface to control the
serialization process but I haven't found good examples on how to do
this yet.




Public Class MyClassExample


Private _MemberVariable_Of_Type_Integer As Integer
Private _MemberVariable_Of_Type_String As String
Private _MemberVariable_Of_Type_Class1 As Class1

Public Property MemberVariable_Of_Type_Integer() As Integer
Get
Return _MemberVariable_Of_Type_Integer
End Get
Set(ByVal value As Integer)
_MemberVariable_Of_Type_Integer = value
End Set
End Property

Public Property MemberVariable_Of_Type_String() As String
Get
Return _MemberVariable_Of_Type_String
End Get

Set(ByVal value As String)
_MemberVariable_Of_Type_String = value
End Set
End Property

Public Property MemberVariable_Of_Type_Class1() As Class1
Get

Return _MemberVariable_Of_Type_Class1
End Get

Set(ByVal value As Class1)
_MemberVariable_Of_Type_Class1 = value
End Set
End Property



Public Sub New()
Me.MemberVariable_Of_Type_Integer = -1
Me.MemberVariable_Of_Type_String = ""
Me.MemberVariable_Of_Type_Class1 = New Class1()
End Sub


End Class
 
B

Bruce Barker

maybe. in your example if class1 is serialiable, you are ok, else you will
fail.

if you mark a class Serializable, you are declaring the class can be
serialized. when serialization happens, each property is serialized using
reflection. if the datatype of the property supports serialization, you're
ok. if not, then serialization will fail.

if a class has a property whose datatype does not support ISerializable, or
some internal values need to be saved, then you need to implement
ISerializable.

for some classes there is no practical way to implement ISerializable, such
a DataReader, or a SQLConnection, or many classes that control unmanged
resources.

-- bruce (sqlwork.com)
 
E

Evian Spring

Thanks it makes sense. When you "some internal values" for Class1 in
my example, you mean the private members of class1?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top