I have two classes:
namespace Something
{
[Serializable]
public class Spec
{
public string Name { get; set; }
[XmlArray]
public List<Value> Values { get; set; }
}
[Serializable]
public class Value
{
public string Name { get; set; }
public short StartPosition { get; set; }
public short EndPosition { get; set; }
public Value(string name, short startPosition, short endPosition)
{
Name = name;
StartPosition = startPosition;
EndPosition = endPosition;
}
}
}
When I try to serialize
var spec = new Spec();
spec.Name = "test";
spec.Values = new List<Value> { new Value("testing", 0, 2) };
var xmls = new XmlSerializer(spec.GetType());
xmls.Serialize(Console.Out, spec);
I get an error:
InvalidOperationException
There was an error reflecting type 'Something.Spec'
Using a list of string
I don't have any problems. Am I missing some attribute?