从包含对象 Friend 的 xml 文件中读取时出现问题!
file.exist() 返回 true 但是当他打开存储时,抛出异常!
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;
}