基本的に、私はユーザー インターフェイスを作成し、ユーザー入力は 2 つのリストに格納されています。
1 つのクラスには両方のリストが含まれており、XMLSerializer
シリアライザーにクラス名だけを渡すことで、適切にネストされたリストを含む XML ファイルを作成しようとしています。
これを実行しようとするたびに、例外が発生します。
InvalidOperationException、XML ドキュメントの生成中にエラーが発生しました
どうすればこれを修正できますか?
コード...
//declared globally
className mInfo = new className(); //create an object that references the class
classTwo aInfo = new assessments(); //used in a seperate method in UI ignore for now.
//end of objects
//start of class - assume is has a constructor for now
[Serializable()]
[XmlRoot]
public class className
{
public string mCode;
public string mTitle;
public int nOC;
public string term;
public string oModM;
public bool hExam;
//create a list to hold the data
[XmlElement]
public List<className> mList = new List<className>();
[XmlElement]
public List<classTwo> aList = new List<classTwo>();
//end of class
//start of writer...
public void XMLWriter()
{
string filePath = "test.xml";
// THIS PART CREATES THE XML FILE
XmlSerializer serializer = new XmlSerializer(typeof(className));
TextWriter textWriter = new StreamWriter(filePath);
serializer.Serialize(textWriter, mInfo);
textWriter.Close();
}
//end of writer