Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / September 2005

Tip: Looking for answers? Try searching our database.

StackOverFlowException - Serialize collection

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
joss - 06 Sep 2005 16:53 GMT
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
joss - 09 Sep 2005 08:41 GMT
any taker? MSFT?
Daniel O'Connell [C# MVP] - 09 Sep 2005 08:51 GMT
> 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?
joss - 09 Sep 2005 09:49 GMT
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 - 09 Sep 2005 10:01 GMT
and it occurs at the line:
"  s.Serialize(writer, MyHistoryStack) "
joss - 12 Sep 2005 16:15 GMT
anybody??
Daniel O'Connell [C# MVP] - 12 Sep 2005 17:51 GMT
> 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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.