C# 读取xml时出现问题:“引用”;System.IO.IsolatedStorage.IsolatedStorageException:不允许在IsolatedStorageFileStream上进行操作;(Windows Phone 8)
在读取包含对象友元的xml文件时,我遇到了一个问题 file.exist()返回true,但当他打开存储时,会引发异常C# 读取xml时出现问题:“引用”;System.IO.IsolatedStorage.IsolatedStorageException:不允许在IsolatedStorageFileStream上进行操作;(Windows Phone 8),c#,xml,asynchronous,windows-phone-8,task,C#,Xml,Asynchronous,Windows Phone 8,Task,在读取包含对象友元的xml文件时,我遇到了一个问题 file.exist()返回true,但当他打开存储时,会引发异常 public static async Task<List<Friend>> Load<Friend>(string file) { IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication(); List&l
public static async Task<List<Friend>> Load<Friend>(string file)
{
IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication();
List<Friend> friend = Activator.CreateInstance<List<Friend>>();
if (storage.FileExists(file))
{
IsolatedStorageFileStream stream = null;
try
{
stream = storage.OpenFile(file, FileMode.Open);
XmlSerializer serializer = new XmlSerializer(typeof(List<Friend>));
friend = (List<Friend>)serializer.Deserialize(stream);
}
catch (Exception)
{
}
finally
{
if (stream != null)
{
stream.Close();
stream.Dispose();
}
}
return friend;
}
return friend;
}
公共静态异步任务加载(字符串文件)
{
IsolatedStorageFile存储=IsolatedStorageFile.GetUserStoreForApplication();
List friend=Activator.CreateInstance();
if(storage.FileExists(file))
{
IsolatedStorageFileStream流=null;
尝试
{
stream=storage.OpenFile(文件,FileMode.Open);
XmlSerializer serializer=新的XmlSerializer(typeof(List));
friend=(列表)序列化程序。反序列化(流);
}
捕获(例外)
{
}
最后
{
if(流!=null)
{
stream.Close();
stream.Dispose();
}
}
回报朋友;
}
回报朋友;
}
您的方法不使用任何异步调用,因此不应将其标记为async
:
public static List<Friend> Load(string file)
{
公共静态列表加载(字符串文件)
{
编译器将警告您,因为您将方法标记为异步,并使其返回
任务
,但您不调用并等待任何异步方法,因此它将始终同步运行。您不了解其中的哪一部分错误?我不明白我必须将等待放在何处谢谢,这删除了警告!但我仍然无法理解t消息:“System.IO.IsolatedStorage.IsolatedStorageException:不允许对IsolatedStorageFileStream执行操作”@GC268DM请参阅以了解更多详细信息