答案 0 :(得分:1)
昨天我遇到了同样的问题。我将我的依赖项切换到库的较低版本,并且工作正常。我最终得到了什么:
MyMessage test = new MyMessage();
DataTable table = new DataTable();
table.TableName = "test";
...init...
test.Fields = table;
using (Stream fs = new FileStream("Test.xml", FileMode.Create))
{
XmlTextWriter writer = new XmlTextWriter(fs, Encoding.UTF8);
writer.Formatting = Formatting.Indented;
new XmlSerializer(typeof(MyMessage)).Serialize(writer, test);
}