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

  • Thread starter Thread starter Evian Spring
  • Start date Start date
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
 
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)
 
Thanks it makes sense. When you "some internal values" for Class1 in
my example, you mean the private members of class1?
 
Back
Top