CRR0028 - Empty event handler

  • 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.

    RemoveQualifier

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

RemoveQualifier

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.

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

        Load += Form1_Load;
    }

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

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.

RemoveQualifier