Collections and Serialization

  • Thread starter Thread starter illsorted
  • Start date Start date
I

illsorted

Guest
Hey all,

Ive written a pretty simple class which inherits from System.Collections.CollectionBase and now Id like to serialize it using the Xml.Serialization.XmlSerializer class so I can write the instance information to disk and retrieve it later.

After I instantiate the class I use this code to try and serialize it (this works with other non-collection classes):

Code:
mySerializer = New Xml.Serialization.XmlSerializer(GetType(CRecipients))
myWriter = New System.IO.StreamWriter("c:\CRecipients.xml")
mySerializer.Serialize(myWriter, oMsg.GetRecipients)

The first line throws the following exception:

An unhandled exception of type System.InvalidOperationException occurred in system.xml.dll

Additional information: Unhandled Exception: System.InvalidOperationException: There was an error reflecting NewCSMailer.CreditSoup.CSMailer.CRecipients. ---> System.InvalidOperationException: You must implement a default accessor on NewCSMailer.CreditSoup.CSMailer.CRecipients because it inherits from ICollection.

----------

Does anyone know what a default accessor is or how I would go about implementing it??

Thanks a bunch,
illsorted
 
Im just guessing, but if you have a Property that is used to Get
and Set the values for your collection, declare the Property
procedure as Default (Default Public Property y(Index As Integer) As String for example).

If you dont have a Property to handle getting and retrieving the
collection data, you need to create one and make it the Default.

I havent worked too much with collections in classes, and once
again this is just an educated guess.

HTH
 
Back
Top