简体   繁体   English

Azure 应用服务上的 500.31 ANCM 故障排除

[英]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 .将项目从ASP.NET Core 3.0升级到ASP.NET Core 3.1后,我的应用程序停止在Azure App Services上工作——但当使用来自Azure DevOps Pipelines持续部署发布时。 ( Similar to another question , it continues to work if I publish directly from Visual Studio.) 与另一个问题类似,如果我直接从 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 :具体来说,管道仍然能够使用Azure 应用服务部署( AzureRmWebAppDeployment ) 任务进行发布,但无法在 Azure 应用服务环境中加载,出现500.32 异常

500.31 ANCM Failed to Find Native Dependencies 500.31 ANCM 找不到原生依赖

Common solutions to this issue:此问题的常见解决方案:

The specified version of Microsoft.NetCore.App or Microsoft.AspNetCore.App was not found.找不到指定版本的 Microsoft.NetCore.App 或 Microsoft.AspNetCore.App。

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.现在,对于未安装 .NET 运行时的情况,我非常熟悉此错误,这在 Microsoft 发布新版本后立即很常见。 In those cases, the typical solution is to either:在这些情况下,典型的解决方案是:

  1. Publish as a --self-contained version of the application, or to作为应用程序的--self-contained版本发布,或者发布到
  2. Enable the appropriate runtime as an App Service Extension , if available.启用适当的运行时作为App Service Extension (如果可用)。

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.在这种情况下,我知道.NET Core 3.1.2 运行时在 App Services 环境中可用,并且还确认这些解决方案无法解决问题。 This indicates a different underlying error.这表明存在不同的潜在错误。

Other threads suggest looking for those details in the Windows Event Viewer ( and here as well ).其他线程建议在 Windows 事件查看器以及此处)中查找这些详细信息。 Since this is an Azure App Service, I instead looked in the App Service Logs .由于这是一个 Azure 应用服务,我反而查看了应用服务日志 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 Application Insights中没有记录任何异常,表明此错误发生在 Application Insights 加载之前。

Given this, my question: How do I troubleshoot 500.31 errors on an Azure App Service?鉴于此,我的问题是:如何解决 Azure 应用服务上的 500.31 错误?

The App Service Logs are not analogous to the Windows Event Viewer ;应用服务日志Windows 事件查看器不同 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.它们将捕获异常,并且对于排除您没有看到的错误很有用,但它们至少不会产生关于 ANCM 错误的附加信息。 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 .相反,您需要确保启用详细错误,以确保您还获得ANCM 检测到特定错误

Enabling detailed errors启用详细错误

In an ASP.NET Core application, detailed errors can be enabled using the UseDeveloperExceptionPage() middleware in the Startup class.在 ASP.NET Core 应用程序中,可以使用Startup类中的UseDeveloperExceptionPage()中间件启用详细错误。 In a standard ASP.NET Core template, they can be conditionally toggled based on an environment variable:在标准的 ASP.NET Core 模板中,它们可以根据环境变量有条件地切换:

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 .在这种情况下,您只需将应用服务配置的ASPNETCORE_ENVIRONMENT配置变量更改为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 500.31 ANCM 无法找到本机依赖项

Common solutions to this issue:此问题的常见解决方案:

The specified version of Microsoft.NetCore.App or Microsoft.AspNetCore.App was not found.未找到指定版本的 Microsoft.NetCore.App 或 Microsoft.AspNetCore.App。

Specific error detected by ANCM: 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'错误:未找到应用程序依赖项清单 (Project.deps.json) 中指定的程序集:包:'Microsoft.Data.SqlClient',版本:'1.0.19269.1' 路径:'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.但关键点是,即使它能够加载正确的 .NET 运行时(在我的例子中是 .NET Core 3.1),它仍然试图从 .NET Core 2.1 运行时加载遗留依赖项,从而触发此错误。 But you won't be able to determine what that dependency is on an Azure App Service unless you first enable the UseDeveloperExceptionPage() .但是除非您首先启用UseDeveloperExceptionPage()否则您将无法确定 Azure 应用服务上的依赖项。

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.在这种情况下,提供对最新Microsoft.Data.SqlClient NuGet 包的显式引用可解决该问题,并允许 Azure 应用服务正确显示站点。

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.也就是说,我仍然不清楚为什么直接从 Visual Studio 发布时这有效,但通过 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 .我知道在使用dotnet publish各种标志时包含的依赖项可能存在细微的差异,因此我的假设是 Visual Studio 和Azure App Service Deploy任务调用dotnet publish的方式存在差异。

In our case it was a logging extension on the app service that needed to be updated to dotnet 5.在我们的例子中,它是需要更新到 dotnet 5 的应用服务上的日志扩展。

在此处输入图片说明

Thanks to @tjaart.感谢@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.在将代码更新为 .NET 5.0 并将 Azure 站点插槽上的运行时更改为 .NET 5.0 后,我遇到了同样的问题然后向我发送有关如何构建 NET 5.0 azure 应用程序的链接!!)我决定在安装到新的 .NET 5 服务器(工作正常)之前在搜索网络时再做一次更改,我看到了这个......我更新日志扩展从 5.0.0-preview-3-20215-14 到 6.0.0-rc-2-21480-10 和服务现在正在运行。

Thanks a million....太感谢了....

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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