Data from IsolatedStorageSettings.ApplicationSettings disappears on return from tombstone
On retu开发者_如何学Gorning from Tombstone, the data in IsolatedStorageSettings.ApplicationSettings is gone.
Any advice or suggestion would be greatly appreciated. Thanks.
Details:
When I try to save into IsolatedStorageSettings.ApplicationSettings a dictionary that maps STRING keys to OBJECT values, after returning from tombstone, all the values from the isolated storage are gone. If I don't try to save that dictionary, there are no problems when returning from Tombstone.
Here is the code:
[DataContract]
[KnownType(typeof(TestClass))]
public class TestClass
{
[DataMember]
public string Property1 { get; private set; }
public TestClass(string prop1)
{
Property1 = prop1;
}
}
public static void AddValuesToIsolatedStorage()
{
IsolatedStorageSettings.ApplicationSettings["Key1"] = 1234;
IsolatedStorageSettings.ApplicationSettings["Key2"] = "abcd";
Dictionary<string, object> dict = new Dictionary<string, object>();
dict.Add("the key", new TestClass("a"));
// IsolatedStorageSettings.ApplicationSettings["Key3"] = dict;
// IsolatedStorageSettings.ApplicationSettings.Save();
}
What I observed (both on the emulator and on my phone - HTC HD7) is that if the 2 lines remain commented out, when I return from Tombstone, IsolatedStorageSettings.ApplicationSettings.Count returns 2 (expected), and both Key1 and Key2 are present.
However, if I uncomment the two lines, upon returning from tombstone, IsolatedStorageSettings.ApplicationSettings.Count returns 0, and neither Key1, nor Key2, nor Key3 are in IsolatedStorageSettings.ApplicationSettings.
Expected: with the two lines uncommented, on returning from tombstone, IsolatedStorageSettings.ApplicationSettings.Count would return 3, and Key1, Key2, and Key3 would be present.
Serialization won't work with readonly properties.
See for instance this WCF question.
精彩评论