2012-10-23 32 views
3

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

例如声纳说:

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 
+0

ICommentPage?怎么样?你还没有发布。 –

+0

从ISerializable派生的任何子类必须实现特殊的构造函数,否则它们将不能正确反序列化。字典,所以你的孩子应该从它的类。 – LightStriker

+0

啊,谢谢你们,我正在研究IDictionary而不是字典。 –

回答

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 
相关问题