Hi everyone,
I am having a problem in the xml serialization of observable collection.
Here is what I am serializing:
public enum Status { Pending, Active, Completed, Cancelled }
public abstract class Entity : INotifyPropertyChanged
{
...
}
public class UserStory : Entity
{
public uint StoryID { get; set; }
public Status Status { get; set; }
...
public ObservableCollection<Task> Tasks { get; set; }
}
public class Task : Entity
{
public uint TaskID { get; set; }
...
}
Here is how I serialize it:
public static void SerializeObjectToXML<T>(T item, string FilePath)
{
XmlSerializer xs = new XmlSerializer(typeof(T));
using (StreamWriter wr = new StreamWriter(FilePath))
{
xs.Serialize(wr, item);
}
}
public class Main()
{
ObservableCollection<UserStory> UserStories { get; set; }
void Main()
{
...
ObservableCollection<object> Document = new ObservableCollection<object>();
Document.Add(UserStories);
SerializeObjectToXML<ObservableCollection<object>>(Document , "...");
...
}
}
But an error occur in the
xs.Serialize(wr, item);
line saying:
InvalidOperation Exception: There was an error generating the XML document.
Inner Exception: The type ScrumPresentor.ObservableCollection`1[[ScrumPresentor.UserStory, ScrumPresentor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] may not be used in this context.
I am using Visual Studio 2010, WPF application in .NET 4.0.
Please, I really need your help.
Thanks in advance.