DisCatSharp Analyzer Rule DCS1302
This rule flags direct .Dispose() calls on DisCatSharp client types that should use await .DisposeAsync() instead.
| Property | Value |
|---|---|
| ID | DCS1302 |
| Severity | Warning |
| Category | Usage |
Why this rule exists
DisCatSharp client types now implement IAsyncDisposable. The async disposal path properly awaits graceful shutdown (disconnecting from the gateway, draining background tasks, releasing HTTP connections) without blocking threads.
Calling Dispose() synchronously internally blocks on DisposeAsync().GetAwaiter().GetResult(), which can cause deadlocks in certain synchronization contexts (e.g., UI threads, ASP.NET classic request contexts).
Code fix
The code fix replaces client.Dispose() with await client.DisposeAsync(). The enclosing method must already be async for the fix to compile.
Before
void Cleanup()
{
client.Dispose();
}
After
async Task CleanupAsync()
{
await client.DisposeAsync();
}
What it doesn't handle
- Making the enclosing method
async— you must do this manually - Adding
ConfigureAwait(false)— add it yourself if needed in library code - Disposal in
finallyblocks or complex control flow