为什么在继承ConfigurationElement时,已标记为[DataContract]的类不可序列化?

时间:2017-01-19 19:21:40

标签: c# .net c#-4.0

我有一个类被装饰为[DataContract],其中一些属性被装饰为[DataMember]。该课程是可序列化的。当我将类更改为从ConfigurationElement继承并将属性更改为[ConfigurationProperty]时,我在下面收到错误。有什么方法可以解决这个问题?我需要实现ISerializable接口吗?感谢您的任何建议。

[DataContract]
public class Setting : ConfigurationElement, ICloneable
{

    [DataMember]
    [ConfigurationProperty("type")]
    public string Type 
    {
        get { return (string)this["type"]; }
        set { this["type"] = value; }
    }
}

错误消息显示:

"Type 'Imaging.Setting' cannot inherit from a type that is not marked with DataContractAttribute or SerializableAttribute.  Consider marking the base type 'System.Configuration.ConfigurationElement' with DataContractAttribute or SerializableAttribute, or removing them from the derived type."

0 个答案:

没有答案