StackOverFlowException - Serialize collection

  • Thread starter Thread starter joss
  • Start date Start date
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
 
joss said:
I'm trying to serialize a Collection (PageHistoryStack) of objects
(PageHistoryItem) and get a StackOverFlowException

Where is the exception occuring? and what is the full stack trace in the
exception?
 
Hi Daniel,

the stack trace is
" at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter
xmlWriter, Object o, XmlSerializerNamespaces namespaces, String
encodingStyle)
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter
xmlWriter, Object o, XmlSerializerNamespaces namespaces)
at System.Xml.Serialization.XmlSerializer.Serialize(TextWriter
textWriter, Object o, XmlSerializerNamespaces namespaces)
at System.Xml.Serialization.XmlSerializer.Serialize(TextWriter
textWriter, Object o)
at ProjectVision.IFrameHistory.Page_Load(Object sender, EventArgs e)
in c:\inetpub\wwwroot\ProjectVision_2\IFrameHistory.aspx.vb:line 46"

the inner exception is
"Exception of type System.StackOverflowException was thrown."
 
joss said:
anybody??

Sorry, I missed your response. My first guess is that your object is
self-referential, that is it contains a reference to itself and thus, when
the serializer trys to serialize it it starts over on its self and
eventually fails.

Outside of that, I couldn't say.
 
Back
Top