First, read Serializing Objects[^] in the .NET Framework SDK. If you attribute a class with SerializableAttribute, by default any private and public fields are serialized, so long as those types are serializable. Since you're deriving from the CollectionBase - which uses the ArrayList internally, which is serializable - your class is already serializable. You don't need to implement ISerializable unless you want to override serialization. The second error is because the Type which is being deserialized is defined in an assembly that cannot be found. Make sure that when deserializing your assembly, your assembly can be found. See How the Runtime Locates Assemblies[^] in the .NET Framework SDK for more information. For the answer to your third question, see the answers above. Mosts lists in the .NET Framework are already serializable. For example, the following creates an XML document with the content of an ArrayList:
using System;
using System.Collections;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Soap;
public class Test
{
static void Main()
{
ArrayList list = new ArrayList();
list.Add("One");
list.Add("Two");
list.Add("Three");
SoapFormatter formatter = new SoapFormatter();
using (Stream s = new FileStream("Test.xml", FileMode.Create))
formatter.Serialize(s, list);
}
}
Microsoft MVP, Visual C# My Articles