Rule S4261: .net core 3.1 false positive on IAsyncEnumerable

protected abstract IAsyncEnumerable<File> GetFilesAsync(string folderName);

Remove the ‘Async’ suffix to the name of this method.

An implemented example of that method is:

protected async override IAsyncEnumerable<File> GetFilesAsync(string folderName)
    var blobServiceClient = new BlobServiceClient(this.ConnectionString);
    var blobContainerClient = blobServiceClient.GetBlobContainerClient(this.Container);

    var blobs = blobContainerClient.GetBlobsAsync(prefix: folderName);

    await foreach (var blob in blobs)
        var blobClient = blobContainerClient.GetBlobClient(blob.Name);
        var blobFile = new BlobFile(blobClient);

        yield return blobFile;

As you can see, the method is indeed async.

1 Like

Hi @MarcusKaseder

I’m not sure I understand what the expected behavior is. Do you expect the issue to be raised also for methods which are returning IAsyncEnumerable<T>?

Hi @costin.zaharia,

sorry, I was not clear with my expected behaviour.

It’s a false positive. So the rule should not fire.
The rule wants to remove the “Async” suffix but it is an async method.

I guess that the rule checks only for Task and ValueTask return types but not for IAsyncEnumerable

You’ll get the error if you just use the following line in an abstract class

protected abstract IAsyncEnumerable<int> GetFilesAsync(string folderName);

Hi @MarcusKaseder,

thanks for your feedback! Based on it we have created a new GitHub issue which you can find here:

The fix will be available in the next release (8.10) which is planned for this Friday (July 17th).

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.