Deserialize generic collections - coming up empty
- by AC
I've got a settings object for my app that has two collections in it. The collections are simple List generics that contain a collection of property bags. When I serialize it, everything is saved with no problem:
XmlSerializer x = new XmlSerializer(settings.GetType());
TextWriter tw = new StreamWriter(@"c:\temp\settings.cpt");
x.Serialize(tw, settings);
However when I deserialize it, everything is restored except for the two collections (verified by setting a breakpoint on the setters:
XmlSerializer x = new XmlSerializer(typeof(CourseSettings));
XmlReader tr = XmlReader.Create(@"c:\temp\settings.cpt");
this.DataContext = (CourseSettings)x.Deserialize(tr);
What would cause this? Everything is pretty vanilla... here's a snippet from the settings object... omitting most of it. The PresentationSourceDirectory works just fine, but the PresentationModules' setter isn't hit:
private string _presentationSourceDirectory = string.Empty;
public string PresentationSourceDirectory {
get { return _presentationSourceDirectory; }
set {
if (_presentationSourceDirectory != value) {
OnPropertyChanged("PresentationSourceDirectory");
_presentationSourceDirectory = value;
}
}
}
private List<Module> _presentationModules = new List<Module>();
public List<Module> PresentationModules {
get {
var sortedModules = from m in _presentationModules
orderby m.ModuleOrder
select m;
return sortedModules.ToList<Module>();
}
set {
if (_presentationModules != value) {
_presentationModules = value;
OnPropertyChanged("PresentationModules");
}
}
}