Click here to Skip to main content
15,888,162 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hello all,

When attempting to serialize my application data, in a Windows Store App I get the following error:
XML
{"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:
C#
[DataContract]
public class SimpleObject
{
    [DataMember]
    private string _Name;
    [DataMember]
    public string Name
    {
        //set the person name
        set { this._Name = value; }
        //get the person name
        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:
C#
_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
Posted
Updated 24-May-13 0:28am
v2

1 solution

Hi Laurence,

I think the below link might helpful to you

http://stackoverflow.com/questions/4875187/datacontract-serialization-exception-data-contract-name-is-not-expected


Regards,
Vinoth Kumar J
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900