# System.Threading.Tasks.TaskCanceledException: A task was canceled. at Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost..ctor

- **ID:** `dotnet/blazor-wasm-prerendering-timeout`
- **Domain:** dotnet
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 85%

## Root Cause

Blazor Server or WASM prerendering times out because the component's OnInitializedAsync method performs a long-running operation (e.g., database call or HTTP request) that exceeds the 30-second default timeout.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| .NET 6.0 | active | — | — |
| .NET 7.0 | active | — | — |
| .NET 8.0 | active | — | — |
| Blazor Server 6.0+ | active | — | — |
| Blazor WASM 6.0+ | active | — | — |

## Workarounds

1. **Configure the Blazor circuit timeout by setting 'CircuitOptions.DisconnectedCircuitRetentionPeriod' and 'CircuitOptions.JSInteropDefaultCallTimeout' in Program.cs to a higher value (e.g., 60 seconds).** (80% success)
   ```
   Configure the Blazor circuit timeout by setting 'CircuitOptions.DisconnectedCircuitRetentionPeriod' and 'CircuitOptions.JSInteropDefaultCallTimeout' in Program.cs to a higher value (e.g., 60 seconds).
   ```
2. **Move long-running operations out of OnInitializedAsync and use OnAfterRenderAsync with a loading state to fetch data after the circuit is established.** (90% success)
   ```
   Move long-running operations out of OnInitializedAsync and use OnAfterRenderAsync with a loading state to fetch data after the circuit is established.
   ```

## Dead Ends

- **Increasing the Kestrel request timeout globally in appsettings.json** — The timeout is specific to Blazor circuit creation, not the HTTP request pipeline, so Kestrel settings have no effect. (60% fail)
- **Adding a try-catch around the entire OnInitializedAsync method to swallow the exception** — The circuit creation is already canceled before the catch block executes, so the component fails to render. (25% fail)
