S4261 has incorrect examples

Both the compliant and noncompliant examples are missing the async modifier for the function. That is what determines if the method should be suffixed with Async or not.

current compliant example

public class Foo
  {
    public Task ReadAsync(byte [] buffer, int offset, int count, CancellationToken cancellationToken)
  }

what it should be

public class Foo
  {
    public async Task ReadAsync(byte [] buffer, int offset, int count, CancellationToken cancellationToken) {}
  }

… though even this is strange as the method name is Read but this doesnt return the result of reading anything.

Hi @StingyJack,

Could you provide some more explanation on why you think this is the case?

Judging from the examples given in the reference in the rule description, it looks to me that async is not required at all.

However, I am not very familiar with this topic (TAP), so I might be mistaken. Maybe the examples in the reference are also incorrect?

Cheers,
Björn

1 Like

I recorded an issue with the official msft docs that’s informing this rule. https://github.com/dotnet/docs/issues/22188

1 Like

So what looks like is that this rule has referenced the example code that is incorrect, and not the section that states the rule.

Asynchronous methods in TAP include the Async suffix after the operation name for methods that return awaitable types, such as Task, Task, ValueTask, and ValueTask. For example, an asynchronous Get operation that returns a Task<String> can be named GetAsync