简体   繁体   中英

Troubleshooting 500.31 ANCM on Azure App Service

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?

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 .

In our case it was a logging extension on the app service that needed to be updated to dotnet 5.

在此处输入图片说明

Thanks to @tjaart. I had the same issue after updating my code to .NET 5.0 and changing the runtime on an Azure site slot to .NET 5.0 I had opened a support ticket and after working with 2 technicians over a week, they could not resolve the issue (other then sending me links on how to build a NET 5.0 azure app!!) I decided to take one more change at searching the web before installing to a new .NET 5 server (which works fine), and I saw this.. I update the logging extension from 5.0.0-preview-3-20215-14 to 6.0.0-rc-2-21480-10 and the service is now working.

Thanks a million....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM