我正在像这样在我的 WP8 应用程序中创建一个空的 xml 文件
public static bool create()
{
Dictionary<string, object> __data = new Dictionary<string, object>();
XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();
xmlWriterSettings.Indent = true;
using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream stream = myIsolatedStorage.OpenFile("Data.xml", FileMode.Create))
{
XmlSerializer serializer = new XmlSerializer(typeof(List<DataModel>));
using (XmlWriter xmlWriter = XmlWriter.Create(stream, xmlWriterSettings))
{
serializer.Serialize(stream, __data);
}
}
}
return true;
}
但我得到一个System.InvalidOperationException
就行了serializer.Serialize(stream, __data);
我究竟做错了什么?
编辑:我在创建新字典后添加了这一行,__data.Add("testkey", "testdatavalue");
但我仍然得到同样的异常。