Note that there are some explanatory texts on larger screens.

plurals
  1. POInvalidOperationException when Serializing
    primarykey
    data
    text
    <p>I get an InvalidOperationException when trying to reflect the "listing" property, as said by inner exception. When it tries to serialize ArmyListing.</p> <p>All the variables are public. Checked List can be serialized. Most errors I found where with people using Dictionaries which can't.</p> <p>Any idea why it appears not to be serializable?</p> <pre><code>//[Serializable] public class ArmyListing { [XmlElement("army")] public List&lt;Army&gt; listing { get; set; } public void SerializeToXML(ArmyListing armyListing) { try { XmlSerializer serializer = new XmlSerializer(typeof(ArmyListing)); TextWriter textWriter = new StreamWriter(@"C:\Test\40k.xml"); serializer.Serialize(textWriter, armyListing); textWriter.Close(); } catch (Exception ex) { } } } //[Serializable] public class Army { //public Army(); [XmlAttribute] [XmlArray("unit-category")] public List&lt;UnitCategory&gt; settingconstraints { get; set; } [XmlAttribute("name")] public string armyName { get; set; } } //[Serializable] public class UnitCategory { //public UnitCategory(); [XmlArray("unit-type")] public List&lt;UnitType&gt; setting { get; set; } [XmlAttribute("name")] public string unitCategoryName { get; set; } } //[Serializable] public class UnitType { //public UnitType(); [XmlArray("unit")] public List&lt;Unit&gt; setting { get; set; } [XmlAttribute("name")] public string unitTypeName { get; set; } } //[Serializable] public class Unit { //public Unit(); [XmlAttribute("name")] public string unitName { get; set; } [XmlAttribute("composition")] public string compsition { get; set; } [XmlAttribute("weapon-skill")] public string weaponSkill { get; set; } [XmlAttribute("ballistic-skill")] public string ballisticSkill { get; set; } [XmlAttribute("strength")] public string strength { get; set; } [XmlAttribute("toughness")] public string T { get; set; } [XmlAttribute("wounds")] public string wounds { get; set; } [XmlAttribute("initiative")] public string initiative { get; set; } [XmlAttribute("attacks")] public string attacks { get; set; } [XmlAttribute("leadership")] public string leadership { get; set; } [XmlAttribute("saving-throw")] public string saveThrow { get; set; } [XmlAttribute("armour")] public string armour { get; set; } [XmlAttribute("weapons")] public string weapons { get; set; } [XmlAttribute("special-rules")] public string specialRules { get; set; } [XmlAttribute("dedicated-transport")] public string dedicatedTransport { get; set; } [XmlAttribute("options")] public string options { get; set; } } //Form namespace ThereIsOnlyRules { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { ArmyListing armyListing = new ArmyListing(); armyListing.SerializeToXML(armyListing); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload