I want to serialize a List on a function like that:
public static void SaveEntriesToDisk(List<IDiaryEntry> entries)
{
using(var configFile = new IsolatedStorageFileStream(FileName, FileMode.Create, FileAccess.Write))
{
var launcherType = entries.GetType();
//write the concrete type so we know what to deserialize
string launcherTypeName = launcherType.AssemblyQualifiedName;
var sw = new StreamWriter(configFile);
sw.WriteLine(launcherTypeName);
//write the object itself
var serializer = new System.Xml.Serialization.XmlSerializer(launcherType);
serializer.Serialize(sw, entries);
}
}
I saw this web: How to Serialize Interfaces in .NET
If I execute this code with one type of IDiaryEntry it is run perfectly but for a List the XmlSerialization throw an exception like that:
...Entities.Contracts.IDiaryEntry cannot be serialized because it is an interface at System.Xml.Serialization.ReflectionHelper.....
Can anybody help me?