Skip to content

Latest commit

 

History

History
76 lines (64 loc) · 1.89 KB

File metadata and controls

76 lines (64 loc) · 1.89 KB

CSL1016: Unsupported use of the AsyncEventHandler attribute.

The AsyncEventHandler attribute can only be used under the following conditions:

  • The attribute only applies to methods.
  • The method must be declared within a class (or record/struct) and a namespace.
  • The method must be async, have a Task return type, and ends with Async.
  • The Task<T> return type is not supported.
  • The method can have parameters, but no modifier is allowed (e.g., ref, out, in, params).
  • Supported attribute arguments are WaitUntilCompletion and UseDispatcher only.
  • An empty list of attribute arguments () is not supported.

Sample code

[AsyncEventHandler()] // CSL1016: Unsupported use of the 'AsyncEventHandler' attribute.
public Task FooAsync() // Not 'async'.
{
    await Task.Delay(0);
}
[AsyncEventHandler()] // CSL1016: Unsupported use of the 'AsyncEventHandler' attribute.
public async void FooAsync() // Not 'Task' return type.
{
    await Task.Delay(0);
}
[AsyncEventHandler()] // CSL1016: Unsupported use of the 'AsyncEventHandler' attribute.
public async Task FooAsynchronous() // Not ending with 'Async'.
{
    await Task.Delay(0);
}
[AsyncEventHandler()] // CSL1016: Unsupported use of the 'AsyncEventHandler' attribute.
public async Task<int> FooAsync() // 'Task<T>' return type.
{
    return await Task.FromResult(0);
}
[AsyncEventHandler] // CSL1016: Unsupported use of the 'AsyncEventHandler' attribute.
public async Task FooAsync(ref object sender) // Modifier (here, 'ref').
{
    await Task.Delay(0);
}
[AsyncEventHandler()] // CSL1016: Unsupported use of the 'AsyncEventHandler' attribute.
public async Task FooAsync()
{
    await Task.Delay(0);
}

Compliant code

namespace MyNamespace;

public class MyClass
{
    [AsyncEventHandler]
    public async Task FooAsync()
    {
        await Task.Delay(0);
    }
}