I'm trying to serialize a Collection (PageHistoryStack) of objects
(PageHistoryItem) and get a StackOverFlowException

following is the Code:

>> Collection:
<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


>> Object:
<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



>> To run it

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

Re: StackOverFlowException - Serialize collection by joss

joss
Fri Sep 09 02:41:48 CDT 2005

any taker? MSFT?


Re: StackOverFlowException - Serialize collection by Daniel

Daniel
Fri Sep 09 02:51:17 CDT 2005


"joss" <josselin.kerviche@gmail.com> wrote in message
news:1126022022.202492.139350@z14g2000cwz.googlegroups.com...
> 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?



Re: StackOverFlowException - Serialize collection by joss

joss
Fri Sep 09 03:49:24 CDT 2005

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."


Re: StackOverFlowException - Serialize collection by joss

joss
Fri Sep 09 04:01:25 CDT 2005

and it occurs at the line:
" s.Serialize(writer, MyHistoryStack) "


Re: StackOverFlowException - Serialize collection by joss

joss
Mon Sep 12 10:15:44 CDT 2005

anybody??


Re: StackOverFlowException - Serialize collection by Daniel

Daniel
Mon Sep 12 11:51:19 CDT 2005


"joss" <josselin.kerviche@gmail.com> wrote in message
news:1126538144.873779.5020@g43g2000cwa.googlegroups.com...
> 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.