serialization of objects in objects 
Author Message
 serialization of objects in objects

How can i save through serialization the state of two (owner created)
objects. If you have a look at the code you will find out that the
BlinkStruct has two instances of another class ColorFillStruct. When I
serialize this i get an error:

"Additional information: Cannot add the same member twice to a
SerializationInfo object."

Does anyone know how to solve this?
I can't find any example that does these things with user defined classed
that must be saved.

Thanks.

<Serializable()> Public Class ColorFillStruct

  Public Color as Color

End Class

<Serializable()> Public Class BlinkStruct
Implements ISerializable
Public ForeColor As ColorFillStruct = Nothing
Public BackColor As ColorFillStruct = Nothing

Public Sub New(ByVal info As SerializationInfo, ByVal context As
StreamingContext)
On Error Resume Next
ForeColor = New ColorFillStruct(info, context)
BackColor = New ColorFillStruct(info, context)
End Sub

Public Sub GetObjectData(ByVal info As SerializationInfo, ByVal context As
StreamingContext) Implements ISerializable.GetObjectData

On Error Resume Next
ForeColor.GetObjectData(info, context)
BackColor.GetObjectData(info, context)  '<= here comes the error
End Sub

End Class



Sat, 20 Nov 2004 13:59:28 GMT  
 serialization of objects in objects
Hi

I have managed to serialize quite a few nested, custom class objects but I
have not implemented the "ISerializable" interface.
Perhaps that is the problem.
<Serializable()> Public Class ConfigGroup

#Region "Local Vars"

Private cOwner As String = ""

Private cName As String = ""

Private cDeadBand As Integer = 0 '% deadband

Private cUpdateRate As Long = 1000 'in milliseconds

Private cIsActive As Boolean = True

Private cIsSubscribed As Boolean = True

Private cTagList As New ConfigTags()

<NonSerialized()> Public WithEvents Opc_grp As OPCGroup

#End Region

    #Region "Constructors"

    Public Sub New()

        End Sub

    Public Sub New(ByVal Owner As String)

    cOwner = Owner

    End Sub

    #End Region

end class

To serialize the object graph I used the following SOAP protocol
Imports System.IO

Imports System.Runtime.Serialization.Formatters.Soap

Public Function SerializeMe(ByVal lPath As String) As Boolean

SerializeMe = True

Dim Fstream As FileStream

Dim Soap1 As SoapFormatter

Try

Fstream = File.Create(lPath)

Soap1 = New SoapFormatter()

Soap1.Serialize(Fstream, ServerConfigs)

Catch Ex As Exception

SerializeMe = False

MsgBox(Ex.Message, MsgBoxStyle.Critical, "Serialization Error")

Finally

Soap1 = Nothing

Fstream.Close()

Fstream = Nothing

End Try

End Function

Why not use this as a guide and see if it works for you.

Good luck

Paul


Quote:
> How can i save through serialization the state of two (owner created)
> objects. If you have a look at the code you will find out that the
> BlinkStruct has two instances of another class ColorFillStruct. When I
> serialize this i get an error:

> "Additional information: Cannot add the same member twice to a
> SerializationInfo object."

> Does anyone know how to solve this?
> I can't find any example that does these things with user defined classed
> that must be saved.

> Thanks.

> <Serializable()> Public Class ColorFillStruct

>   Public Color as Color

> End Class

> <Serializable()> Public Class BlinkStruct
> Implements ISerializable
> Public ForeColor As ColorFillStruct = Nothing
> Public BackColor As ColorFillStruct = Nothing

> Public Sub New(ByVal info As SerializationInfo, ByVal context As
> StreamingContext)
> On Error Resume Next
> ForeColor = New ColorFillStruct(info, context)
> BackColor = New ColorFillStruct(info, context)
> End Sub

> Public Sub GetObjectData(ByVal info As SerializationInfo, ByVal context As
> StreamingContext) Implements ISerializable.GetObjectData

> On Error Resume Next
> ForeColor.GetObjectData(info, context)
> BackColor.GetObjectData(info, context)  '<= here comes the error
> End Sub

> End Class



Thu, 25 Nov 2004 23:07:20 GMT  
 serialization of objects in objects
thanks for your help

i'll investigate it.


Quote:
> Hi

> I have managed to serialize quite a few nested, custom class objects but I
> have not implemented the "ISerializable" interface.
> Perhaps that is the problem.
> <Serializable()> Public Class ConfigGroup

> #Region "Local Vars"

> Private cOwner As String = ""

> Private cName As String = ""

> Private cDeadBand As Integer = 0 '% deadband

> Private cUpdateRate As Long = 1000 'in milliseconds

> Private cIsActive As Boolean = True

> Private cIsSubscribed As Boolean = True

> Private cTagList As New ConfigTags()

> <NonSerialized()> Public WithEvents Opc_grp As OPCGroup

> #End Region

>     #Region "Constructors"

>     Public Sub New()

>         End Sub

>     Public Sub New(ByVal Owner As String)

>     cOwner = Owner

>     End Sub

>     #End Region

> end class

> To serialize the object graph I used the following SOAP protocol
> Imports System.IO

> Imports System.Runtime.Serialization.Formatters.Soap

> Public Function SerializeMe(ByVal lPath As String) As Boolean

> SerializeMe = True

> Dim Fstream As FileStream

> Dim Soap1 As SoapFormatter

> Try

> Fstream = File.Create(lPath)

> Soap1 = New SoapFormatter()

> Soap1.Serialize(Fstream, ServerConfigs)

> Catch Ex As Exception

> SerializeMe = False

> MsgBox(Ex.Message, MsgBoxStyle.Critical, "Serialization Error")

> Finally

> Soap1 = Nothing

> Fstream.Close()

> Fstream = Nothing

> End Try

> End Function

> Why not use this as a guide and see if it works for you.

> Good luck

> Paul



> > How can i save through serialization the state of two (owner created)
> > objects. If you have a look at the code you will find out that the
> > BlinkStruct has two instances of another class ColorFillStruct. When I
> > serialize this i get an error:

> > "Additional information: Cannot add the same member twice to a
> > SerializationInfo object."

> > Does anyone know how to solve this?
> > I can't find any example that does these things with user defined
classed
> > that must be saved.

> > Thanks.

> > <Serializable()> Public Class ColorFillStruct

> >   Public Color as Color

> > End Class

> > <Serializable()> Public Class BlinkStruct
> > Implements ISerializable
> > Public ForeColor As ColorFillStruct = Nothing
> > Public BackColor As ColorFillStruct = Nothing

> > Public Sub New(ByVal info As SerializationInfo, ByVal context As
> > StreamingContext)
> > On Error Resume Next
> > ForeColor = New ColorFillStruct(info, context)
> > BackColor = New ColorFillStruct(info, context)
> > End Sub

> > Public Sub GetObjectData(ByVal info As SerializationInfo, ByVal context
As
> > StreamingContext) Implements ISerializable.GetObjectData

> > On Error Resume Next
> > ForeColor.GetObjectData(info, context)
> > BackColor.GetObjectData(info, context)  '<= here comes the error
> > End Sub

> > End Class



Fri, 10 Dec 2004 21:49:29 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Object Serialization not working as expected

2. Object Persistance/Serialization

3. Object serialization

4. Binary Serialization with an object that has events

5. Object serialization

6. object serialization to/from a dataset

7. object serialization

8. word doc object serialization

9. Returning Dataset to ASP.NET from .NET Component / Business Object Serialization

10. Using same mechanism for object serialization and DB persistence

11. Object Serialization

12. VB Object serialization

 

 
Powered by phpBB® Forum Software