Serialize object with byte array

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

My class is inheriting from a class that implements ISerializable.

My problem is in deserialising the image data kept in a local byte array variable.

Here is the code:

Public Sub New(ByVal Info As SerializationInfo, ByVal Context As StreamingContext)
MyBase.New(Info, Context)
Dim temp1() As Byte
m_Picture = CType(Info.GetValue("Picture", temp1.GetType()), Byte())
End Sub

Public Overrides Sub GetObjectData(ByVal info As SerializationInfo, ByVal context As StreamingContext)
MyBase.GetObjectData(info, context)
info.AddValue("Picture", m_Picture, m_Picture.GetType())
End Sub

When deserializing, the call to Info.GetValue returns a NullReferenceException - "Object reference not set to an instance of an object"

What am I doing wrong here?

Also, I want to be able to pass an object in to COM+ for transactional processing for the purposes of saving the contents of an entire object graph to database (this object above is part of a collection to the master object) Should I still be using ISerializable or should I also have the IDeSerialization callback interface as well?
 
Simply forget the temp1
Use GetType(Byte()) instead of temp1.GetType()

markeboy said:
My class is inheriting from a class that implements ISerializable.

My problem is in deserialising the image data kept in a local byte array variable.

Here is the code:

Public Sub New(ByVal Info As SerializationInfo, ByVal Context As StreamingContext)
MyBase.New(Info, Context)
Dim temp1() As Byte
m_Picture = CType(Info.GetValue("Picture", temp1.GetType()), Byte())
End Sub

Public Overrides Sub GetObjectData(ByVal info As SerializationInfo, ByVal context As StreamingContext)
MyBase.GetObjectData(info, context)
info.AddValue("Picture", m_Picture, m_Picture.GetType())
End Sub

When deserializing, the call to Info.GetValue returns a
NullReferenceException - "Object reference not set to an instance of an
object"
What am I doing wrong here?

Also, I want to be able to pass an object in to COM+ for transactional
processing for the purposes of saving the contents of an entire object graph
to database (this object above is part of a collection to the master object)
Should I still be using ISerializable or should I also have the
IDeSerialization callback interface as well?
 
Back
Top