This should not create an error (sharplab):
using System.Threading.Tasks;
class C
{
static async Task M()
{
// ❌ CS0518: Predefined type 'System.IAsyncDisposable' is not defined or imported
await using (new C()) { }
}
public Task DisposeAsync() => Task.CompletedTask;
}
The workaround is to declare some unused type named System.IAsyncDisposable. It doesn't have to contain any members and it doesn't even have to be an interface (sharplab):
using System;
using System.Threading.Tasks;
class C
{
static async Task M()
{
await using (new C()) { }
}
public Task DisposeAsync() => Task.CompletedTask;
}
namespace System
{
public enum IAsyncDisposable
{
}
}
This should not create an error (sharplab):
The workaround is to declare some unused type named System.IAsyncDisposable. It doesn't have to contain any members and it doesn't even have to be an interface (sharplab):