我有一个 Windows 8 应用程序。这个应用程序有几个自定义的类。我需要将这些实例的实例存储到独立存储中。据我了解,隔离存储已被 ApplicationDataContainer 取代。目前,我正在尝试以下方法:
public class MyClass
{
private HttpClient service = new HttpClient();
public string FirstName { get; set; }
public DateTime? BirthDate { get; set; }
public int Gender { get; set; }
public async Task Save()
{
// Do stuff...
}
}
...
MyClass myInstance = new MyInstance();
// do stuff...
try {
ApplicationDataContainer storage = ApplicationData.Current.LocalSettings;
if (storage != null)
{
if (storage.Values.ContainsKey("MyKey"))
storage.Values["MyKey"] = myInstance;
else
storage.Values.Add("MyKey", myInstance);
}
} catch (Exception ex)
{
MessageDialog dialog = new MessageDialog("Unable to save to isolated storage");
dialog.ShowAsync();
}
我错过了什么。为什么总是抛出异常。例外不是很具有描述性。它只是一个通用的 System.Exception 并且该消息也无济于事。有人可以帮帮我吗?
谢谢