Compiler Error WFO5002

'System.Windows.Forms.Form.ShowAsync' is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.

This compiler error is generated when using any of the following methods:

  • Form.ShowAsync
  • Form.ShowDialogAsync
  • TaskDialog.ShowDialogAsync

The Windows Forms asynchronous API is currently experimental and subject to change. This error is generated so that you understand the implications of writing code that uses these APIs. The error must be suppressed to continue. For more information about this API, see Async forms.

Example

The following sample generates WFO5002:

private async void button1_Click(object sender, EventArgs e)
{
    Form1 newDialog = new();
    await newDialog.ShowAsync();
}

To correct this error

Suppress the error and enable access to the API by either of the following methods:

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

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

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

  • Add the following PropertyGroup to your project file to suppress the error:

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

    private async void button1_Click(object sender, EventArgs e)
    {
        Form1 newDialog = new();
    #pragma warning disable WFO5002
        await newDialog.ShowAsync();
    #pragma warning restore WFO5002
    }