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
.