Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing a Dictionary<TKey, TValue> in isolated storage

I'm hitting a server and getting some data, am parsing this data and storing it in a Dictionary<TKey, TValue>.

I store this Dictionary<TKey, TValue> list in Isolated storage. Now, the problem is whenever am trying retrieve the Dictionary<TKey, TValue> (in 2nd run) what ever I have stored in the 1st run, the values for each key in the bean would have become null. I dunno whether the way am storing the Dictionary<TKey, TValue> is wrong.

Code sample:

CacheManager.getInstance().PersistData(CacheManager.SERVICE_TABLE, 
    dictionaryList);

public void PersistData(string storageName, object dict)
{
    try
    {
        PersistDataStore.Add(storageName, dict);
        PersistDataStore.Save();
    }
    catch (Exception ex)
    {
    }
}
like image 368
Apoorva Avatar asked Nov 21 '25 01:11

Apoorva


1 Answers

I got the solution to the problem, the members of the dictionary dict must be serialized. i.e.,

using System.Runtime.Serialization;
[DataContact]
public class classname()
{
[datamember]
public int propertyname;
}
like image 188
Apoorva Avatar answered Nov 22 '25 14:11

Apoorva