Click here to Skip to main content
15,888,113 members
Home / Discussions / C#
   

C#

 
AnswerRe: how to add lists Pin
BillWoodruff7-Dec-11 10:11
professionalBillWoodruff7-Dec-11 10:11 
QuestionEmail Exception Catching Pin
AmbiguousName6-Dec-11 20:48
AmbiguousName6-Dec-11 20:48 
AnswerRe: Email Exception Catching Pin
Wayne Gaylard6-Dec-11 21:18
professionalWayne Gaylard6-Dec-11 21:18 
AnswerRe: Email Exception Catching Pin
AmbiguousName6-Dec-11 21:47
AmbiguousName6-Dec-11 21:47 
GeneralRe: Email Exception Catching Pin
Richard MacCutchan6-Dec-11 22:19
mveRichard MacCutchan6-Dec-11 22:19 
GeneralRe: Email Exception Catching Pin
Wayne Gaylard6-Dec-11 22:20
professionalWayne Gaylard6-Dec-11 22:20 
AnswerRe: Email Exception Catching Pin
Dan Mos6-Dec-11 22:25
Dan Mos6-Dec-11 22:25 
QuestionSerialization Problem Pin
Kevin Marois6-Dec-11 13:45
professionalKevin Marois6-Dec-11 13:45 
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<FolderModel> Folders { get; set; }
    public List<FileModel> Files { get; set; }
    public bool IsExpanded { get; set; }

    public FolderModel()
    {
        Folders = new List<FolderModel>();
        Files = new List<FileModel>();
    }
}


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

AnswerRe: Serialization Problem Pin
BillWoodruff6-Dec-11 16:30
professionalBillWoodruff6-Dec-11 16:30 
AnswerRe: Serialization Problem Pin
Mycroft Holmes6-Dec-11 19:20
professionalMycroft Holmes6-Dec-11 19:20 
AnswerRe: Serialization Problem Pin
Dan Mos6-Dec-11 20:50
Dan Mos6-Dec-11 20:50 
AnswerRe: Serialization Problem Pin
Pete O'Hanlon6-Dec-11 20:59
mvePete O'Hanlon6-Dec-11 20:59 
GeneralRe: Serialization Problem Pin
Kevin Marois7-Dec-11 5:22
professionalKevin Marois7-Dec-11 5:22 
GeneralRe: Serialization Problem Pin
Pete O'Hanlon7-Dec-11 5:25
mvePete O'Hanlon7-Dec-11 5:25 
GeneralRe: Serialization Problem Pin
BillWoodruff7-Dec-11 10:34
professionalBillWoodruff7-Dec-11 10:34 
QuestionHow to fetch the user filled fields in PDF form Pin
Ravi k rao6-Dec-11 9:58
Ravi k rao6-Dec-11 9:58 
AnswerRe: How to fetch the user filled fields in PDF form Pin
Not Active6-Dec-11 11:54
mentorNot Active6-Dec-11 11:54 
AnswerRe: How to fetch the user filled fields in PDF form Pin
Wonde Tadesse6-Dec-11 13:09
professionalWonde Tadesse6-Dec-11 13:09 
GeneralRe: How to fetch the user filled fields in PDF form Pin
Ravi k rao6-Dec-11 21:25
Ravi k rao6-Dec-11 21:25 
QuestionHow to pass null ref type. Pin
__John_6-Dec-11 3:18
__John_6-Dec-11 3:18 
AnswerRe: How to pass null ref type. Pin
Luc Pattyn6-Dec-11 4:17
sitebuilderLuc Pattyn6-Dec-11 4:17 
AnswerRe: How to pass null ref type. Pin
BobJanova6-Dec-11 4:21
BobJanova6-Dec-11 4:21 
GeneralRe: How to pass null ref type. Pin
__John_6-Dec-11 4:36
__John_6-Dec-11 4:36 
GeneralRe: How to pass null ref type. Pin
BobJanova6-Dec-11 5:34
BobJanova6-Dec-11 5:34 
GeneralRe: How to pass null ref type. Pin
DaveyM696-Dec-11 7:07
professionalDaveyM696-Dec-11 7:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.