小编use*_*885的帖子

序列化Observable Collection时出错

我有一个可观察的集合,我正在尝试序列化到磁盘.收到的错误是:

 Type 'VisuallySpeaking.Data.GrammarList' with data contract name
 'GrammarList:http://schemas.datacontract.org/2004/07/VisuallySpeaking.Data'
 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."}  System.Exception
 {System.Runtime.Serialization.SerializationException}
Run Code Online (Sandbox Code Playgroud)

这是我的数据对象:

namespace VisuallySpeaking.Data
{

    [CollectionDataContract]
    public class GrammarList : ObservableCollection<GrammarDataObject>
{
    public GrammarList() : base()
    {
        Add(new GrammarDataObject("My Name", "My name is","Assets/SampleAssets/MyName.png"));
        Add(new GrammarDataObject("Where is", "Where is",""));
        Add(new GrammarDataObject("Dog", …
Run Code Online (Sandbox Code Playgroud)

c# wcf observablecollection datacontractserializer windows-store-apps

5
推荐指数
1
解决办法
981
查看次数