C# 如何在Windows Phone 8中创建空xml
我正在WP8应用程序中创建一个空xml文件,如下所示C# 如何在Windows Phone 8中创建空xml,c#,xml,windows-phone-8,xml-serialization,C#,Xml,Windows Phone 8,Xml Serialization,我正在WP8应用程序中创建一个空xml文件,如下所示 public static bool create() { Dictionary<string, object> __data = new Dictionary<string, object>(); XmlWriterSettings xmlWriterSettings = new XmlWriterSettings(); xmlWriterSetting
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;
}
publicstaticboolcreate()
{
字典_data=新字典();
XmlWriterSettings XmlWriterSettings=新的XmlWriterSettings();
xmlWriterSettings.Indent=true;
使用(IsolatedStorage File myIsolatedStorage=IsolatedStorage File.GetUserStoreForApplication())
{
使用(IsolatedStorageFileStream=myIsolatedStorage.OpenFile(“Data.xml”,FileMode.Create))
{
XmlSerializer serializer=新的XmlSerializer(typeof(List));
使用(XmlWriter=XmlWriter.Create(流,xmlWriterSettings))
{
serializer.Serialize(流、数据);
}
}
}
返回true;
}
但是我在serializer.Serialize(流,u数据)行上得到了一个System.invalidoOperationException
代码>
我做错了什么
Edit:我在创建新字典\u data.Add(“testkey”、“testdatavalue”)后添加了这一行代码>但我仍然得到相同的异常。我们有
Dictionary<string, object> __data = ...
XmlSerializer serializer = new XmlSerializer(typeof(List<DataModel>));
serializer.Serialize(stream, __data);
字典数据=。。。
XmlSerializer serializer=新的XmlSerializer(typeof(List));
serializer.Serialize(流、数据);
因此,序列化程序用于另一种类型(DataModel
)。它不会处理字典
添加测试项。“这可能与空虚无关。”亨克奥尔特曼我刚刚添加了一个编辑。这就是你想让我做的吗?是的,现在我们知道这不是关于“空”的。我在这里贴了一个后续问题