ASP.NET Core - Error trying to use HealthChecks

You'll have to configure the health check infrastructure services via the AddHealthChecks() extension method. For example:

public void ConfigureServices(IServiceCollection services)
{
    services.AddHealthChecks();
}

Also see the documentation.


In my case the health checks UI itself not launching and crashing the .net core 3.1 web API application.

Error Message: Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: HealthChecks.UI.Core.Notifications.IHealthCheckFailureNotifier Lifetime: Scoped ImplementationType: HealthChecks.UI.Core.Notifications.WebHookFailureNotifier': Unable to resolve service for type 'HealthChecks.UI.Core.Data.HealthChecksDb' while attempting to activate 'HealthChecks.UI.Core.Notifications.WebHookFailureNotifier'.)

Fix: Add any UI storage provider . In my case I have choosen AddInMemoryStorage()

Startup.cs

    public void ConfigureServices(IServiceCollection services)
    {
        ...
        
        services.AddHealthChecks() 
            .AddDbContextCheck<PollDbContext>() //nuget: Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore
            .AddApplicationInsightsPublisher(); //nuget: AspNetCore.HealthChecks.Publisher.ApplicationInsights
    
        services.AddHealthChecksUI() //nuget: AspNetCore.HealthChecks.UI
            .AddInMemoryStorage(); //nuget: AspNetCore.HealthChecks.UI.InMemory.Storage
            
        ...
    }
    
    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        ...
        
        app.UseHealthChecks("/healthcheck", new HealthCheckOptions
        {
            Predicate = _ => true,
            ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse //nuget: AspNetCore.HealthChecks.UI.Client
        });
        
        //nuget: AspNetCore.HealthChecks.UI
        app.UseHealthChecksUI(options =>
        {
            options.UIPath = "/healthchecks-ui";
            options.ApiPath = "/health-ui-api";
        });
        ...
    }

appsettings.json

    "HealthChecks-UI": {
        "DisableMigrations": true,
        "HealthChecks": [
            {
                "Name": "PollManager",
                "Uri": "/healthcheck"
            }
        ],
        "Webhooks": [
            {
                "Name": "",
                "Uri": "",
                "Payload": "",
                "RestoredPayload": ""
            }
        ],
        "EvaluationTimeOnSeconds": 10,
        "MinimumSecondsBetweenFailureNotifications": 60,
        "MaximumExecutionHistoriesPerEndpoint": 15
    }