J
joss
I'm trying to serialize a Collection (PageHistoryStack) of objects
(PageHistoryItem) and get a StackOverFlowException
following is the Code:
<Serializable()> Public Class PageHistoryStack
Inherits System.Collections.CollectionBase
#Region "Constructors"
Public Sub New()
End Sub
#End Region
#Region "Public Properties"
Default Public Overridable Property Item(ByVal index As Integer) As
PageHistoryItem
Get
Return DirectCast(Item(index), PageHistoryItem)
End Get
Set(ByVal value As PageHistoryItem)
Item(index) = value
End Set
End Property
#End Region
#Region "Public Functions"
'Needed for the XMLSerialization
Public Overridable Function Add(ByVal value As PageHistoryItem) As
Integer
Me.InnerList.Add(value)
End Function
<Serializable()> Public Class PageHistoryItem
#Region "Constructors"
Public Sub New()
End Sub
Public Sub New(ByVal ContainerID As Integer, ByVal ProjectID As
Integer, ByVal URL As String)
mURL = URL
mContainerId = ContainerID
mProjectId = ProjectID
End Sub
#End Region
#Region "Private Members"
Private mURL As String
Private mContainerId, mProjectId As Integer
#End Region
#Region "Public Properties"
Public Property ContainerId() As Integer
Get
Return mContainerId
End Get
Set(ByVal value As Integer)
mContainerId = value
End Set
End Property
Public Property ProjectId() As Integer
Get
Return mProjectId
End Get
Set(ByVal value As Integer)
mProjectId = value
End Set
End Property
Public Property URL() As String
Get
Return mURL
End Get
Set(ByVal Value As String)
mURL = Value
End Set
End Property
#End Region
End Class
Try
Dim MyHistoryStack As New PageHistoryStack
MyHistoryStack.Add(New PageHistoryItem(12, 1, "wbs.aspx"))
MyHistoryStack.Add(New PageHistoryItem(12, 2, "wbs.aspx"))
MyHistoryStack.Add(New PageHistoryItem(12, 3, "wbs.aspx"))
MyHistoryStack.Add(New PageHistoryItem(12, 4, "wbs.aspx"))
' Create a new XmlSerializer instance.
Dim s As New XmlSerializer(GetType(PageHistoryStack))
' Writing the XML file to disk requires a TextWriter.
Dim writer As New StreamWriter(Server.MapPath("lucky.xml"))
' Serialize the object, and close the StreamWriter.
s.Serialize(writer, MyHistoryStack)
writer.Close()
Catch ex As Exception
End Try
Any help appreciated,
Joss
(PageHistoryItem) and get a StackOverFlowException
following is the Code:
<Serializable()> Public Class PageHistoryStack
Inherits System.Collections.CollectionBase
#Region "Constructors"
Public Sub New()
End Sub
#End Region
#Region "Public Properties"
Default Public Overridable Property Item(ByVal index As Integer) As
PageHistoryItem
Get
Return DirectCast(Item(index), PageHistoryItem)
End Get
Set(ByVal value As PageHistoryItem)
Item(index) = value
End Set
End Property
#End Region
#Region "Public Functions"
'Needed for the XMLSerialization
Public Overridable Function Add(ByVal value As PageHistoryItem) As
Integer
Me.InnerList.Add(value)
End Function
<Serializable()> Public Class PageHistoryItem
#Region "Constructors"
Public Sub New()
End Sub
Public Sub New(ByVal ContainerID As Integer, ByVal ProjectID As
Integer, ByVal URL As String)
mURL = URL
mContainerId = ContainerID
mProjectId = ProjectID
End Sub
#End Region
#Region "Private Members"
Private mURL As String
Private mContainerId, mProjectId As Integer
#End Region
#Region "Public Properties"
Public Property ContainerId() As Integer
Get
Return mContainerId
End Get
Set(ByVal value As Integer)
mContainerId = value
End Set
End Property
Public Property ProjectId() As Integer
Get
Return mProjectId
End Get
Set(ByVal value As Integer)
mProjectId = value
End Set
End Property
Public Property URL() As String
Get
Return mURL
End Get
Set(ByVal Value As String)
mURL = Value
End Set
End Property
#End Region
End Class
Try
Dim MyHistoryStack As New PageHistoryStack
MyHistoryStack.Add(New PageHistoryItem(12, 1, "wbs.aspx"))
MyHistoryStack.Add(New PageHistoryItem(12, 2, "wbs.aspx"))
MyHistoryStack.Add(New PageHistoryItem(12, 3, "wbs.aspx"))
MyHistoryStack.Add(New PageHistoryItem(12, 4, "wbs.aspx"))
' Create a new XmlSerializer instance.
Dim s As New XmlSerializer(GetType(PageHistoryStack))
' Writing the XML file to disk requires a TextWriter.
Dim writer As New StreamWriter(Server.MapPath("lucky.xml"))
' Serialize the object, and close the StreamWriter.
s.Serialize(writer, MyHistoryStack)
writer.Close()
Catch ex As Exception
End Try
Any help appreciated,
Joss