Skip to content
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

Don't assert on async delegate #4613

Open
Evangelink opened this issue Jan 10, 2025 · 1 comment · May be fixed by #4640
Open

Don't assert on async delegate #4613

Evangelink opened this issue Jan 10, 2025 · 1 comment · May be fixed by #4640

Comments

@Evangelink
Copy link
Member

Evangelink commented Jan 10, 2025

Summary

Add a new analyzer similar to VSTHRD101 that would warn when an assertion is done is done in an async delegate call.

Background and Motivation

See example below, based off some customer code base:

internal delegate Call(string id);

[TestClass]
public class TestClass
{
    [TestMethod]
    public void M()
    {
        Call c = async s => Assert.IsNotNull(await GetData(s).ConfigureAwait(false));
        c("nok");
    }

    private Task<object?> GetData(string s)
    {
        if (s == "nok") return Task.FromResult<object?>(null);
        return Task.FromResult(new object());
    }
}

Proposed Feature

Add an analyzer

AB#2340735

@Youssef1313
Copy link
Member

We should probably do it for async void in general, and not delegates specifically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants