Skip to main content
ai-slop/csharp-async-voidmanual fix

Async void method.

An `async void` method. Callers cannot await it, and an exception thrown inside it escapes every caller's try/catch and can crash the process.

Flagged shape and clean shape.

Each example shows the exact code shape the rule is looking for, then the smallest version that keeps the intent without hiding risk or adding noise.

csharp-async-void.cs
✗ Flagged
public async void SaveOrder(Order order)
{
    await _repository.InsertAsync(order);
    await _bus.PublishAsync(new OrderSaved(order.Id));
}
Why this trips

Deterministic line match on masked source: flags `async void Name(` declarations.

csharp-async-void.cs
✓ Clean
public async Task SaveOrderAsync(Order order)
{
    await _repository.InsertAsync(order);
    await _bus.PublishAsync(new OrderSaved(order.Id));
}
What changed

Return `Task` (or `Task<T>`) so callers can await and observe failures. If it must be `void` for an event, make sure the body cannot throw.

Agents mark a method `async` to use `await` inside and leave the return type as `void` because nothing is returned. The compiler accepts it without complaint.

How this rule is justified.

Rule id

ai-slop/csharp-async-void

Enforcing engine

ai-slop

Detector strategy

Deterministic line match on masked source: flags `async void Name(` declarations.

Legitimate code that is NOT flagged

Event handlers are not flagged: names starting with `On` and a capital letter, ending in `Handler`, or containing an underscore (such as `button1_Click`), and signatures that mention `EventArgs`.

Evidence

Part of aislop's C# rule set. First-class C# support, including C#-specific AI-slop rules, arrived in aislop v0.14.1.