🔧 Fix an IAsyncDisposable Never Awaited Inside a Using Block
A type that implements both IDisposable and IAsyncDisposable can be entered with a plain synchronous using statement without the compiler objecting, since the synchronous interface is still technically satisfied — but if the type’s synchronous Dispose() was only ever implemented as a thin fallback (or worse, left empty on the assumption everyone would use await using), the connection, stream, or handle it wraps never actually gets released by the synchronous path.
🔎 The Problem
public class ManagedConnection : IDisposable, IAsyncDisposable
{
public void Dispose() { /* intentionally minimal - async path assumed */ }
public async ValueTask DisposeAsync() => await _inner.CloseAsync();
}
using var conn = new ManagedConnection(); // compiles fine!
// Dispose() runs at scope exit, but it does almost nothing -
// the actual cleanup logic only exists in DisposeAsync(), unused here
✅ Fix: Use await using Wherever the Real Cleanup Lives
- Change the declaration to
await using var conn = new ManagedConnection();inside an async method, which callsDisposeAsync()at scope exit instead of the synchronous stub. - If synchronous disposal must remain supported for callers who can’t await, implement
Dispose()properly as its own complete cleanup path rather than leaving it as a thin, assumed-unused fallback — don’t let one interface silently depend on the other being used instead. - Add a code analyzer rule (or review checklist item) flagging a type that implements both interfaces where
Dispose()andDisposeAsync()don’t perform equivalent cleanup, since the compiler itself gives no warning when only the weaker one gets called.
Implementing IAsyncDisposable doesn’t retire IDisposable — whichever one the call site actually uses is the only one that runs.



