Question

I am creating a Windows 8 app that needs to contain two main types of data - List<Project> and List<User>, where Project and User are data models containing different types of data (including Lists of other objects etc).

I have previously been making Windows Phone apps, and there I simply used the application settings to store data in similar scenarios. So I hoped that would work in Windows 8 as well.

I have elected to use the ApplicationData.Current.LocalSettings-structure to save my app data. However, whenever I try to save my data, I get this type of error:

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.

The models are marked with [DataContract] attributes if that makes any difference.

As far as I have understood Microsoft, only standard data types (like booleans, strings etc) can be saved in this fashion. Is this correct?

And if so, how could I save data structured in this way?

Help would be greatly appreciated!

Was it helpful?

Solution

Complex types will cause a bit of grief, I cannot confirm that it isn't possible, but there are other options.

In situations where I want to store application data without the overhead of a database engine I use serialization. Depending on the composition of your types (boil down to simple data types and have public getter/setters) you can use XML serialization and/or binary serialization.

XML serialization can be preferable in situations where it's handy to be able to review (edit) the data outside of the scope of the application. (debugging, etc.) However it imposes more limitations on the data unless you opt for hand-coding custom serializers. Binary serialization is more flexible, and combined with compression and encryption gives you more a compact/disguised/secured data storage option. (A bit extra cost in time to compress/decompress and encryption if used.)

Unfortunately binary won't be that well suited to stick something into local application data without doing something like converting it first into a Base64 string. (Results in a potentially huge blob of text) Typically with serialization options I look at saving files in a nominated folder that the user has sufficient permissions for.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top