Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why a class does not implement ISerializable interface violates MissingSerializationConstructorRule

We have sonar reports that says many of the classes in our projects violates the MissingSerializationConstructorRule, however neither the class nor its base class implement any of the Iserializable interface, anyone has any idea why?

for example, sonar says:

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

where the corresponding class is

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

Two interfaces does not implement ISerializable either, i.e.

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

public interface IRmdsPublicationPage : IDictionary<string, object>, IDisposable
like image 862
Fan Jia Avatar asked Jul 17 '26 17:07

Fan Jia


1 Answers

Dictionary(TKey, TValue) implements 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
like image 67
RB. Avatar answered Jul 20 '26 05:07

RB.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!