المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Serialization Problem



C# Programming
12-07-2011, 11:30 AM
I have 3 classes:

[Serializable]public class _ModelBase{ public Guid Id { get; set; } public string Caption { get; set; } public string Description { get; set; } public bool IsActive { get; set; } public int Sequence { get; set; } public ImageSource Image { get; set; }}
and

[Serializable]public class FolderModel : _ModelBase{ public List Folders { get; set; } public List Files { get; set; } public bool IsExpanded { get; set; } public FolderModel() { Folders = new List(); Files = new List(); }}
and

[Serializable]public class FileModel : _ModelBase{ public string FileName { get; set; }}
I'm trying to serialize a a collection of FolderModels and FileModels:

private void saveAppDataToFile(){ using (TextWriter textWriter = new StreamWriter(xmlDataFile)) { XmlSerializer serializer = new XmlSerializer(typeof(FolderModel)); serializer.Serialize(textWriter, Folders); textWriter.Close(); }}
I'm gettng the runtime error
"There was an error generating the XML document." "Unable to cast object of type 'System.Collections.Generic.List`1[MyApp.Models.FolderModel]' to type 'MyApp.Models.FolderModel'"}
I can't figure out why this won't work. Anyone see what's wrong?

Thanks
Everything makes sense in someone's mind