502.5 cloud runtime_error ai_generated true

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

ID: cloud/azure-app-service-http-502-bad-gateway

Also available as: JSON · Markdown · 中文
80%Fix Rate
85%Confidence
1Evidence
2023-06-20First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
Azure App Service Windows active
.NET 6 active
.NET 8 active
ASP.NET Core Module 18.0 active

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.

generic

中文

托管在 Azure 应用服务上的 ASP.NET Core 应用程序因缺少运行时依赖项、启动命令不正确或应用程序与 IIS ANCM 模块之间的端口不匹配而无法启动。

Official Documentation

https://learn.microsoft.com/en-us/troubleshoot/azure/app-service/web-apps-open-source-technologies-faqs#http-error-5025---ancm-out-of-process-startup-failure

Workarounds

  1. 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.
    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. 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`.
    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`.

中文步骤

  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.
  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`.

Dead Ends

Common approaches that don't work:

  1. 90% fail

    The application binary or its dependencies are still broken; restarting only re-executes the same failing startup sequence.

  2. 65% 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.