对Azure App Service上的500.31 ANCM进行故障排除 [英] Troubleshooting 500.31 ANCM on Azure App Service

查看:410
本文介绍了对Azure App Service上的500.31 ANCM进行故障排除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将项目从 ASP.NET Core 3.0 升级到 ASP.NET Core 3.1 后,我的应用程序停止在 Azure App Services 上工作了—但使用 Azure DevOps Pipelines 中的连续部署发布时,仅 . (与另一个问题类似,如果我直接从Visual Studio发布,则可以正常工作.)

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

特别是,管道仍然可以使用 Azure App Service部署(AzureRmWebAppDeployment)任务进行发布,但是它无法使用

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无法找到本地依赖项

此问题的常用解决方案:

找不到指定版本的Microsoft.NetCore.App或Microsoft.AspNetCore.App.

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.

现在,对于未安装.NET Runtime的情况,我非常熟悉此错误,这在Microsoft发布新版本后立即很常见.在这种情况下,典型的解决方案是:

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. 发布为应用程序的--self-contained版本,或发布为
  2. 启用适当的运行时作为 App服务扩展(如果有).
  1. Publish as a --self-contained version of the application, or to
  2. Enable the appropriate runtime as an App Service Extension, if available.

在这种情况下,我知道 .NET Core 3.1.2运行时在App Services环境中可用,并且还确认这些解决方案不能解决问题.这表明存在其他潜在错误.

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.

其他线程建议在Windows事件查看器中查找这些详细信息(

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.

鉴于此,我的问题是:如何解决Azure应用服务上的500.31错误?

推荐答案

应用服务日志 Windows事件查看器类似;它们将捕获异常,并且对于排除您未发现的错误很有用,但是至少它们不会为ANCM错误提供其他信息.相反,您需要确保启用了详细的错误,以确保您还获得了ANCM检测到的特定错误.

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.

在ASP.NET Core应用程序中,可以使用Startup类中的UseDeveloperExceptionPage()中间件来启用详细的错误.在标准的ASP.NET Core模板中,可以根据环境变量有条件地切换它们:

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();
    }
  }
}

在这种情况下,您只需要将App Service配置的ASPNETCORE_ENVIRONMENT配置变量更改为Development.

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

注意:这样做会暴露有关 all 异常的详细信息,并可能导致潜在的安全漏洞.仅应在其他情况下受保护的开发环境中启用此功能,或在面向公众的服务器上将其作为临时故障排除技术启用.

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无法找到本地依赖项

此问题的常用解决方案:

找不到指定版本的Microsoft.NetCore.App或Microsoft.AspNetCore.App.

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.

错误:找不到在应用程序依赖项清单(Project.deps.json)中指定的程序集:包:'Microsoft.Data.SqlClient',版本:'1.0.19269.1'路径:'runtimes/win/lib/netcoreapp2.1/Microsoft.Data.SqlClient.dll'

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'

现在,您的应用程序正在寻找的确切基础依赖关系可能会有所不同.但是关键点在于,即使它能够加载正确的.NET Runtime(在我的情况下为.NET Core 3.1),它仍在尝试从.NET Core 2.1运行时加载旧版依赖项,从而触发此错误.但是除非首先启用UseDeveloperExceptionPage(),否则您将无法确定该依赖关系对Azure App Service的影响.

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().

实际的解决方案显然取决于您收到的确切错误.在这种情况下,提供对最新Microsoft.Data.SqlClient NuGet程序包的显式引用即可解决此问题,并允许Azure App Service正确显示站点.

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.

也就是说,我仍然不清楚为什么在直接从Visual Studio直接发布时可以奏效,但是在通过Azure DevOps管道发布时却失败了.我知道使用dotnet publish的各种标志时所包含的依赖项之间可能会有细微的差异,因此我的假设是Visual Studio和 Azure App Service部署任务调用.

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.

这篇关于对Azure App Service上的500.31 ANCM进行故障排除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆