Table of Contents

DisCatSharp Analyzer Rule DCS1301

This rule flags using statements on DisCatSharp client types that should be await using for proper async disposal.

Property Value
ID DCS1301
Severity Warning
Category Usage

Why this rule exists

DisCatSharp client types (DiscordClient, DiscordShardedClient, DiscordOAuth2Client, DiscordWebhookClient) now implement IAsyncDisposable. Using await using instead of using ensures that resources (HTTP connections, WebSockets, background tasks) are released asynchronously without blocking threads.

The sync Dispose() path internally calls DisposeAsync().GetAwaiter().GetResult(), which can cause deadlocks in some synchronization contexts.

Code fix

The code fix replaces using with await using. The enclosing method must already be async for the fix to compile.

Before

void Run()
{
    using var client = new DiscordClient(new DiscordConfiguration { ... });
    // ...
}

After

async Task RunAsync()
{
    await using var client = new DiscordClient(new DiscordConfiguration { ... });
    // ...
}

What it doesn't handle

  • Making the enclosing method async — you must do this manually
  • using statements in synchronous entry points (e.g., Main) where async is not practical