# HTTP Error 502.5 - ANCM Out-Of-Process Startup Failure

- **ID:** `cloud/azure-app-service-http-502-bad-gateway`
- **Domain:** cloud
- **Category:** runtime_error
- **Error Code:** `502.5`
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

ASP.NET Core application hosted on Azure App Service fails to start due to missing runtime dependencies, incorrect startup command, or port mismatch between the application and the IIS ANCM module.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Azure App Service Windows | active | — | — |
| .NET 6 | active | — | — |
| .NET 8 | active | — | — |
| ASP.NET Core Module 18.0 | active | — | — |

## Workarounds

1. **Enable detailed error logging via `appsettings.json`: set `"ASPNETCORE_DETAILEDERRORS": "true"` and `"ASPNETCORE_ENVIRONMENT": "Development"` in the App Settings blade; then redeploy and check the stdout log at `D:\home\LogFiles\stdout\`. Fix any missing NuGet packages or framework versions.** (85% success)
   ```
   Enable detailed error logging via `appsettings.json`: set `"ASPNETCORE_DETAILEDERRORS": "true"` and `"ASPNETCORE_ENVIRONMENT": "Development"` in the App Settings blade; then redeploy and check the stdout log at `D:\home\LogFiles\stdout\`. Fix any missing NuGet packages or framework versions.
   ```
2. **Ensure the application listens on the correct port by adding `UseUrls` in `Program.cs` or setting the `PORT` environment variable to `8080` (the default port ANCM expects). Example: `webBuilder.UseUrls("http://*:8080");` in `CreateHostBuilder`.** (80% success)
   ```
   Ensure the application listens on the correct port by adding `UseUrls` in `Program.cs` or setting the `PORT` environment variable to `8080` (the default port ANCM expects). Example: `webBuilder.UseUrls("http://*:8080");` in `CreateHostBuilder`.
   ```

## Dead Ends

- **** — The application binary or its dependencies are still broken; restarting only re-executes the same failing startup sequence. (90% fail)
- **** — The stdout log may show generic messages; the actual error (e.g., 'Could not load file or assembly') is often written to stderr or the Windows Event Log. (65% fail)
