Back to Devexpress

CRR0028 - Empty event handler

coderushforroslyn-119685-static-code-analysis-analyzers-library-crr0028-empty-event-handler.md

latest1.9 KB
Original Source

CRR0028 - Empty event handler

  • Feb 28, 2025
  • 2 minutes to read

This analyzer detects the event handlers that contain no code or throw a NotImplementedException exception. Specify accessibility levels for the event handler methods in the CodeRush options dialog:

  • Open the Editor | C# (Visual Basic) | Code Analysis | Unused Code Analysis options page.
  • Specify accessibility levels for members. For example, check the private option and uncheck other options for members accessibility to allow this analyzer to detect empty private event handlers only.

The following example demonstrates how the analyzer detects an empty private event handler.

Tip

Use the Highlight unused code in editor check box in the Editor | C# (Visual Basic) | Code Analysis | General option page to enable or disable the highlighting of empty event handler in the code editor.

To fix this issue, add some code to the event handler or delete it along with the subscription statement.

csharp
public partial class Form1 : Form {
    public Form1() {
        InitializeComponent();

        Load += Form1_Load;
    }

    private void Form1_Load(object sender, EventArgs e) {
        BackColor = Color.Black;
    }
}
vb
Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        BackColor = Color.Black
    End Sub
End Class

How to Enable the Diagnostic

Choose Empty event handler in the Editor | C# (Visual Basic) | Code Analysis | Code Issues Catalog options page and check the Enabled checkbox.

See Also

Suppress Analyzers