Troubleshooting 500.31 ANCM on Azure App Service

╄→尐↘猪︶ㄣ 提交于 2020-04-07 07:05:52

问题


After upgrading a project from ASP.NET Core 3.0 to ASP.NET Core 3.1, my application stopped working on Azure App Services—but only when published using continuous deployment from Azure DevOps Pipelines. (Similar to another question, it continues to work if I publish directly from Visual Studio.)

Specifically, the pipeline is still able to publish using the Azure App Service Deploy (AzureRmWebAppDeployment) task, but it fails to load in the Azure App Service environment with a 500.32 exception:

500.31 ANCM Failed to Find Native Dependencies

Common solutions to this issue:

The specified version of Microsoft.NetCore.App or Microsoft.AspNetCore.App was not found.

Now, I'm quite familiar with this error for cases where the .NET Runtime is not installed, as is common immediately after Microsoft releases new versions. In those cases, the typical solution is to either:

  1. Publish as a --self-contained version of the application, or to
  2. Enable the appropriate runtime as an App Service Extension, if available.

In this case, I know the .NET Core 3.1.2 runtime is available in the App Services environment, and have additionally confirmed that these solutions don't resolve the issue. This indicates a different underlying error.

Other threads suggest looking for those details in the Windows Event Viewer (and here as well). Since this is an Azure App Service, I instead looked in the App Service Logs. Those only included a copy of the above error, however, without any further details. Further, there are no exceptions logged in Azure Application Insights, suggesting this error is occurring prior to Application Insights loading.

Given this, my question: How do I troubleshoot 500.31 errors on an Azure App Service?


回答1:


The App Service Logs are not analogous to the Windows Event Viewer; they will capture the exceptions, and are useful for troubleshooting errors that you did not witness, but they won't yield additional information for ANCM errors, at least. Instead, you'll need to ensure that detailed errors are enabled in order to ensure that you're also getting the specific error detected by ANCM.

Enabling detailed errors

In an ASP.NET Core application, detailed errors can be enabled using the UseDeveloperExceptionPage() middleware in the Startup class. In a standard ASP.NET Core template, they can be conditionally toggled based on an environment variable:

public class Startup {
  …
  public static void Configure(IApplicationBuilder app, IWebHostEnvironment env) {
    if (env.IsDevelopment()) {
      app.UseDeveloperExceptionPage();
    }
  }
}

In that case, you just need to change your App Service configuration's ASPNETCORE_ENVIRONMENT configuration variable to Development.

Note: Doing this exposes details about all exceptions and can lead to potential security vulnerabilities. This should only be enabled for otherwise-secured development environments, or as a temporary troubleshooting technique on a public-facing server.

Specific error detected

In my case, this exposed the following:

500.31 ANCM Failed to Find Native Dependencies

Common solutions to this issue:

The specified version of Microsoft.NetCore.App or Microsoft.AspNetCore.App was not found.

Specific error detected by ANCM:

Error: An assembly specified in the application dependencies manifest (Project.deps.json) was not found: package: 'Microsoft.Data.SqlClient', version: '1.0.19269.1' path: 'runtimes/win/lib/netcoreapp2.1/Microsoft.Data.SqlClient.dll'

Now, the exact underlying dependency that your application is looking for will likely be different. But the critical point is that even though it's able to load the correct .NET Runtime (.NET Core 3.1 in my case), it's still trying to load a legacy dependency from the .NET Core 2.1 runtime, thus triggering this error. But you won't be able to determine what that dependency is on an Azure App Service unless you first enable the UseDeveloperExceptionPage().

Resolving the issue

The actual solution will obviously depend on the exact error you're receiving. In this case, providing an explicit reference to the latest Microsoft.Data.SqlClient NuGet package solves the problem, and allows the Azure App Service to display the site correctly.

That said, it remains unclear to me why this worked when publishing directly from Visual Studio, but fails when publishing via an Azure DevOps Pipeline. I know there can be subtle differences in what dependencies are included when using various flags of dotnet publish, so my assumption is that there's a difference between how Visual Studio and the Azure App Service Deploy task call dotnet publish.



来源:https://stackoverflow.com/questions/60839745/troubleshooting-500-31-ancm-on-azure-app-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!