Results 1 to 5 of 5

Thread: Serialization of Collections

  1. #1

    Thread Starter
    PowerPoster sunburnt's Avatar
    Join Date
    Feb 2001
    Location
    Boulder, Colorado
    Posts
    1,403

    Serialization of Collections

    Back to this :P

    I've noticed that when I try to serialize a Private Collection, I recieve no error -- it just doesn't save correctly. Now, I tried this:
    VB Code:
    1. <Serializable()> Public Class Test
    2.     Public R As New Collection()
    3.     Public M As String
    4. End Class
    5.  
    6.    Private Sub SaveSettings(ByRef mypath As String, ByRef myObject As Object)
    7.         Dim XmlS As XmlSerializer
    8.         Dim fStream As IO.FileStream
    9.         'Try
    10.  
    11.         XmlS = New XmlSerializer(myObject.GetType)
    12.         fStream = New IO.FileStream(mypath, IO.FileMode.Create)
    13.         XmlS.Serialize(fStream, myObject)
    14.         fStream.Close()
    15.     End Sub
    16.  
    17.         'CODE
    18.         Dim f As New Test()
    19.         f.R.Add("hi")
    20.         f.m = ":-)"
    21.         SaveSettings("C:\f.xml", f)

    Which finally throws an error.
    System.InvalidOperationException: There was an error reflecting 'MoW.Test'. ---> System.InvalidOperationException: You must implement the Add(System.Object) method on Microsoft.VisualBasic.Collection because it inherits from ICollection.

    What does this mean?
    Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.

  2. #2
    Lively Member
    Join Date
    Aug 1999
    Location
    Amsterdam
    Posts
    117
    When a class implements the ICollection interface it must include an Add method and Item property to be Serializable.

  3. #3

    Thread Starter
    PowerPoster sunburnt's Avatar
    Join Date
    Feb 2001
    Location
    Boulder, Colorado
    Posts
    1,403
    Right...so how would I go about doing that?
    Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.

  4. #4
    Lively Member
    Join Date
    Aug 1999
    Location
    Amsterdam
    Posts
    117
    ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemxmlserializationxmlserializerclasstopic.htm

  5. #5

    Thread Starter
    PowerPoster sunburnt's Avatar
    Join Date
    Feb 2001
    Location
    Boulder, Colorado
    Posts
    1,403
    thanks for your help.
    Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width