Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I store List<T> in local settings?

Currently i am using the following method to store the data which compiles successfully

App.removalList.Add(new RemoveFavourites(App.user.auth_token, App.user.user_id, proid.ToString()));

ApplicationData.Current.LocalSettings.Values["Remove_fav_properties_list"] = App.removalList;

It compiles successfully however i am getting the following error at runtime:

WinRT information: Error trying to serialize the value to be written to the application data store.
Additional information: Data of this type is not supported.

Following is the RemoveFavourites Class:

public class RemoveFavourites
{

    public string auth_token { get; set; }

    public string user_id { get; set; }

    public string property_id { get; set; }

    public RemoveFavourites(string auth_token, string user_id, string property_id)
    {
        this.auth_token = auth_token;
        this.user_id = user_id;
        this.property_id = property_id;
    }
}

and the complete exception is

An exception of type 'System.Exception' occurred in mscorlib.ni.dll but was not handled in user code WinRT information: Error trying to serialize the value to be written to the application data store Additional information: Data of this type is not supported. Error trying to serialize the value to be written to the application data store If there is a handler for this exception, the program may be safely continued.

like image 801
Bilal Amjad Avatar asked Dec 16 '15 09:12

Bilal Amjad


1 Answers

You can not store complex objects in app settings. (reference)

Try to serialize the object (maybe using json or custom way of serializing you have implemented yourself) and then store the data.

like image 130
Hamid Pourjam Avatar answered Oct 06 '22 23:10

Hamid Pourjam