Compiler Warning WFDEV004

Version introduced: .NET 10 Preview 1

Form.OnClosing, Form.OnClosed and the corresponding events are obsolete. Use Form.OnFormClosing, Form.OnFormClosed, Form.FormClosing and Form.FormClosed instead.

These methods and events are provided for backwards compatibility and they shouldn't be used. Instead, reference the replacement methods and events.

Workaround

Replace the obsolete member with the new member:

Old member New member
Form.OnClosing Form.OnFormClosing
Form.OnClosed Form.OnFormClosed
Form.Closing Form.FormClosing
Form.Closed Form.FormClosed

Suppress a warning

Suppress the warning with either of the following methods:

  • Set the severity of the rule in the .editorConfig file.

    [*.{cs,vb}]
    dotnet_diagnostic.WFDEV004.severity = none
    

    For more information about editor config files, see Configuration files for code analysis rules.

  • Add the following PropertyGroup to your project file:

    <PropertyGroup>
        <NoWarn>$(NoWarn);WFDEV004</NoWarn>
    </PropertyGroup>
    
  • Suppress in code with the #pragma warning disable WFDEV004 directive.

For more information, see How to suppress code analysis warnings.