Edit

Share via


Compiler Error CS1983

The return type of an async method must be void, Task, Task<T>, a task-like type (A task-like type is one that adheres to the pattern, described here, required by the C# specification), IAsyncEnumerable<T>, or IAsyncEnumerator<T>

Example

The following sample generates CS1983:

// CS1983.cs (4,62)
using System.Collections.Generic;

class C
{
    static async IEnumerable<int> M()
    {
        yield return await Task.FromResult(1);
    }
}

Since IEnumerable.GetEnumerator returns an IEnumerator<T> whose MoveNext method does not return a value of Task<T>, it is not compatible with an async method.

To correct this error

Use an interface that results in the invocation of method that returns a type of Task<T>, for example, IAsyncEnumerable<T>:

using System.Collections.Generic;

class C
{
    static async IAsyncEnumerable<int> M()
    {
        yield return await Task.FromResult(1);
    }
}