We have the followig code:
[Serializable]
public class Class1
{
[XmlElement(\"description\")]
public string Description { get; set; }
}
class Program
Use an XmlTypeAttribute on the class as well:
[XmlType(TypeName="ElementName")]
[Serializable]
public class Class1 { ...
EDIT: Updated from XmlRootAttribute
to XmlTypeAttribute
. The former works where the type being passed to the serialiser is the attributed type (Class1
here), but not when there is a wrapping type (List
here). That XmlType
works is not clear from the documentation (my emphasis):
Controls the XML schema that is generated when the attribute target is serialized by the XmlSerializer.
Credit to Bala R's answer.