none
Code analysis rule CA2229 does not detect missing serialization constructors on exception classes

    Frage

  • Hi everybody!

    When I forgot to implement the "serialization constructor" for a class that inherits from an "ISerializable implementing class" (e.g. Dictionary), then the code analysis rule CA2229 correctly detected this fault. But if this class inherits from Exception-Class (which also implements ISerializable), this is not detected by code analysis. Why?

    Is this a bug inside the code analysis rule?

    Regards

    Oliver

    <Serializable>
    Public Class MyException
      Inherits Exception
    
      ' Missing serialization constructors --> Violation of CA2229 is NOT detected --> ERROR?
    
      'Protected Sub New(info As Runtime.Serialization.SerializationInfo, context As Runtime.Serialization.StreamingContext)
      '  MyBase.New(info, context)
      'End Sub
    
    End Class
    
    
    <Serializable>
    Public Class MyDictionary
      Inherits Dictionary(Of Int32, String)
    
      ' Missing serialization constructors --> Violation of CA2229 is detected --> CORRECT!
    
      'Protected Sub New(info As Runtime.Serialization.SerializationInfo, context As Runtime.Serialization.StreamingContext)
      '  MyBase.New(info, context)
      'End Sub
    
    End Class
    

    Mittwoch, 16. März 2016 13:24

Antworten

Alle Antworten