I'm attempting to serialize (and subsequently deserialize) a rather simple class to an XML string, but am getting an exception: "The type System.Collections.Generic.List`1[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] may not be used in this context."
The method I'm using to serialize is:
public string ToXml(TaskListFilterConfig config)
{
Type[] extraTypes = { typeof(FilterConfig), typeof(SortConfig) };
XmlSerializer serializer = new XmlSerializer(config.GetType(), extraTypes);
using (StringWriter writer = new StringWriter())
{
serializer.Serialize(writer, config);
return writer.ToString();
}
}
The classes I'm attempting to serialize are:
[XmlRoot(ElementName = "TaskListFilterConfig", IsNullable = false)]
[XmlInclude(typeof(FilterConfig))]
[XmlInclude(typeof(SortConfig))]
public class TaskListFilterConfig
{
[XmlArray("FilterConfigList")]
[XmlArrayItem("FilterConfig")]
public List<FilterConfig> FilterConfigList { get; set; }
[XmlArray("SortConfigList")]
[XmlArrayItem("SortConfig")]
public List<SortConfig> SortConfigList { get; set; }
public TaskListFilterConfig()
{
FilterConfigList = new List<FilterConfig>();
SortConfigList = new List<SortConfig>();
}
}
[XmlType("FilterConfig")]
public class FilterConfig
{
public OperandType Operand { get; set; }
public int SelectedOperatorIndex { get; set; }
public int SelectedColumnIndex { get; set; }
public object RightOperand { get; set; }
public FilterConfig() { }
}
[XmlType("SortConfig")]
public class SortConfig
{
public Infragistics.Windows.Controls.SortStatus SortDirection { get; set; }
public int ColumnSelectedIndex { get; set; }
public SortConfig() { }
}