为什么类没有实现ISerializable接口违反了MissingSerializationConstructorRule

时间:2012-10-23 13:13:30

标签: c# serializable

我们有声纳报告说我们项目中的许多类都违反了MissingSerializationConstructorRule,但是类和基类都没有实现任何Iserializable接口,任何人都知道为什么?

例如,声纳说:

public class CommentPage : RmdsPublicationPage, ICommentPage 
    { 
 *MissingSerializationConstructorRule    
 The required constructor for ISerializable is not present in this type.* 
    public CommentPage() 
    { 
        this["COMMENTTXT"] = null; 

其中相应的类是

public class CommentPage : RmdsPublicationPage, ICommentPage
{
    public CommentPage()
    {
        // do something
    }
    public void Update(string comment)
    {
        //something else
    }
}

两个接口也没有实现ISerializable,即

public class RmdsPublicationPage : Dictionary<string, object>, IRmdsPublicationPage

public interface IRmdsPublicationPage : IDictionary<string, object>, IDisposable

1 个答案:

答案 0 :(得分:3)

Dictionary(TKey, TValue)实现了ISerializable

[SerializableAttribute]
[ComVisibleAttribute(false)]
public class Dictionary<TKey, TValue> : IDictionary<TKey, TValue>, 
    ICollection<KeyValuePair<TKey, TValue>>, IDictionary, ICollection, 
    IReadOnlyDictionary<TKey, TValue>, IReadOnlyCollection<KeyValuePair<TKey, TValue>>, 
    IEnumerable<KeyValuePair<TKey, TValue>>, IEnumerable, ISerializable, 
    IDeserializationCallback