All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.plugins.vbnet.S3927.html Maven / Gradle / Ivy

There is a newer version: 10.5.0.109200
Show newest version

Why is this an issue?

Serialization event handlers that don’t have the correct signature will not be called, bypassing augmentations to automated serialization and deserialization events.

A method is designated a serialization event handler by applying one of the following serialization event attributes:

Serialization event handlers take a single parameter of type StreamingContext, return void, and have private visibility.

This rule raises an issue when any of these constraints are not respected.

How to fix it

Code examples

Noncompliant code example

<Serializable>
Public Class Foo
    <OnSerializing>
    Public Sub OnSerializing(ByVal context As StreamingContext) ' Noncompliant: should be private
    End Sub

    <OnSerialized>
    Private Function OnSerialized(ByVal context As StreamingContext) As Integer '  Noncompliant: should return void
    End Function

    <OnDeserializing>
    Private Sub OnDeserializing() ' Noncompliant: should have a single parameter of type StreamingContext
    End Sub

    <OnSerializing>
    Public Sub OnSerializing2(Of T)(ByVal context As StreamingContext) ' Noncompliant: should have no type parameters
    End Sub

    <OnDeserialized>
    Private Sub OnDeserialized(ByVal context As StreamingContext, ByVal str As String) ' Noncompliant: should have a single parameter of type StreamingContext
    End Sub
End Class

Compliant solution

<Serializable>
Public Class Foo
    <OnSerializing>
    Private Sub OnSerializing(ByVal context As StreamingContext)
    End Sub

    <OnSerialized>
    Private Sub OnSerialized(ByVal context As StreamingContext)
    End Sub

    <OnDeserializing>
    Private Sub OnDeserializing(ByVal context As StreamingContext)
    End Sub

    <OnDeserialized>
    Private Sub OnDeserialized(ByVal context As StreamingContext)
    End Sub
End Class

Resources

Documentation





© 2015 - 2025 Weber Informatics LLC | Privacy Policy