Skip to content

WFO2001: Analyzer doesn't trigger the 'wrong async overload' warning with implicit member access. #13237

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Tracked by #13160 ...
KlausLoeffelmann opened this issue Apr 4, 2025 · 0 comments
Assignees
Labels
area-Analyzers/CodeFixes A Roslyn Analyzer is either needed for the context, needs to be scope extended or fixed.

Comments

@KlausLoeffelmann
Copy link
Member

There are 2 ways to use InvokeAsync - from the outside, which always needs explicit member access, and from the inside, which can be using explicit member access (this or Me in VB), but usually, we do not do it and use it implicitly. Inside most Microsoft repos, .editorconfig is even configures to make the explicit usage where implicit is possible an error (see code sample below).

For the implicit member access, the WFO2001 Analyzer is not being triggered.

// Example 1: Explicit member access (control.InvokeAsync)
private async void UpdateButtonFromBackgroundThread()
{
    var result = await Task.Run(() => PerformLongRunningOperation())
                           .ConfigureAwait(false);
    
    // Explicit access is necessary - we need to define the instance.
>>> await button1.InvokeAsync(() => {
        button1.Text = result;
        button1.Enabled = true;
    });
}

// Example 2: Implicit use from within a Form
private async void MyForm_Load(object sender, EventArgs e)
{
    var data = await Task.Run(() => FetchDataFromDatabase())
                        .ConfigureAwait(false);
    
    // .editorconfig is often configured to have including this/me causing an error.
    // We have to InvokeAsync often as implicit member access.
>>> await [this.]InvokeAsync(() => {
        dataGridView1.DataSource = data;
        statusLabel.Text = "Data loaded successfully";
    });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Analyzers/CodeFixes A Roslyn Analyzer is either needed for the context, needs to be scope extended or fixed.
Projects
None yet
Development

No branches or pull requests

1 participant