0
私はスーパークラスと2つのサブクラスを持っていると私はリストとしてサブクラスのオブジェクトをシリアライズし、デシリアライズしたいです例外的に終わった。XMLシリアル化は
これを行う方法はありますか?
Type1 t = new Type1() { text="123" ,opt1=true,opt2=true};
Type2 t1 = new Type2() { text="1234",isAnswer=false};
Question q1 = new Question() { text="12321"};
Question q2 = new Question() { text = "12321" };
List<Question> q = new List<Question>() { t1 };
FileStream fs = new FileStream("aa.xml", FileMode.OpenOrCreate, FileAccess.Write);
XmlSerializer xs = new XmlSerializer(typeof(List<Question>));
//Exception is generated here InvalidOperationException
//there was error genearating the XML document
xs.Serialize(fs, q);
fs.Close();
あなたのコードはどのように見えますか?何を試しましたか?どんな例外がありましたか?あなたの質問はあなたのシナリオを再現するのに十分な詳細を私たちに与えるものではありません。 – RQDQ
何の例外がありましたか? –
InvalidoperationException XMLドキュメントの生成中にエラーが発生しました。 Type1 t =新しいType1(){text = "123"、opt1 = true、opt2 = true}; タイプ2 t1 =新しいタイプ2(){テキスト= "1234"、isAnswer = false}; 質問q1 =新しい質問(){text = "12321"}; 質問q2 =新しい質問(){text = "12321"}; リスト q =新しいリスト(){q1、q2、t1}; FileStream fs = new FileStream( "aa.xml"、FileMode.OpenOrCreate、FileAccess.Write); XmlSerializer xs =新しいXmlSerializer(typeof(List )); –
Guruparan