> ## Documentation Index
> Fetch the complete documentation index at: https://ancplua.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# AL0105 - Avoid blocking calls in async methods

> .Result/.Wait()/.GetAwaiter().GetResult() can deadlock in async code

Source: [Al0105AvoidBlockingCallsInAsyncAnalyzer.cs](https://github.com/ANcpLua/ANcpLua.Analyzers/blob/main/src/ANcpLua.Analyzers/Analyzers/Al0105AvoidBlockingCallsInAsyncAnalyzer.cs)

## Description

Calling `.Result`, `.Wait()`, or `.GetAwaiter().GetResult()` inside an async method can cause deadlocks, especially in contexts with a `SynchronizationContext`.

## Bad Code

```csharp theme={null}
async Task<string> GetData()
{
    var result = httpClient.GetStringAsync("/api").Result;
    return result;
}
```

## Good Code

```csharp theme={null}
async Task<string> GetData()
{
    var result = await httpClient.GetStringAsync("/api");
    return result;
}
```

## Properties

* **Category**: Threading
* **Severity**: Warning
* **Enabled by default**: True
* **Code fix available**: False

## Configuration

```editorconfig theme={null}
dotnet_diagnostic.AL0105.severity = warning
```
