Hello all,
When attempting to serialize my application data, in a Windows Store App I get the following error:
{"Type 'MyObject' with data contract name '' is not expected. Consider using a DataContractResolver or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer."}
I have already tried to decorate the class in question using the relevant tags, in the following way:
[DataContract]
public class SimpleObject
{
[DataMember]
private string _Name;
[DataMember]
public string Name
{
set { this._Name = value; }
get { return this._Name; }
}
}
As well as this, in the
SuspensionManager
class I explicitly added my custom object to the
_knownTypes
list inside the
SaveAsync()
method in the following way:
_knownTypes.Add(typeof(SimpleObject));
However, I am still getting this error. Does anyone have any suggestions?
While researching this problem I have read the following posts:
Storing something other than a string in SuspensionManager.SessionState
SerializationException serializing newtonsoft jobject with DataContractSerializer
Thanks in advance for any suggestions.
Cheers,
Larry
EDIT:
I have found a great article (finally) with a worked example. I've tweaked it so it performs the serialization on termination of the app but the actual serialization code is clean and seems to work well.
Example Metro app /WinRT: Serializing and deseralizing objects using XMLSerializer to StorageFile and LocalFolder using generics and async/await threading