You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I added a MySQL health check to a simple ASP.NET 8.0 Web API project. When accessing the health check URL I got the following exception:
InvalidOperationException: Unable to resolve service for type 'HealthChecks.MySql.MySqlHealthCheckOptions' while attempting to activate 'HealthChecks.MySql.MySqlHealthCheck'.
Microsoft.Extensions.DependencyInjection.ActivatorUtilities+ConstructorMatcher.CreateInstance(IServiceProvider provider)
Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateInstance(IServiceProvider provider, Type instanceType, object[] parameters)
Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetServiceOrCreateInstance<T>(IServiceProvider provider)
Microsoft.Extensions.Diagnostics.HealthChecks.DefaultHealthCheckService.RunCheckAsync(HealthCheckRegistration registration, CancellationToken cancellationToken)
Microsoft.Extensions.Diagnostics.HealthChecks.DefaultHealthCheckService.RunCheckAsync(HealthCheckRegistration registration, CancellationToken cancellationToken)
Microsoft.Extensions.Diagnostics.HealthChecks.DefaultHealthCheckService.CheckHealthAsync(Func<HealthCheckRegistration, bool> predicate, CancellationToken cancellationToken)
Microsoft.AspNetCore.Diagnostics.HealthChecks.HealthCheckMiddleware.InvokeAsync(HttpContext httpContext)
Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)
What you expected to happen:
Expected that URL would return Healthy.
How to reproduce it (as minimally and precisely as possible):
Source code sample:
services.AddMySqlDataSource(builder.Configuration.GetConnectionString("mysql"));
services.AddHealthChecks()
.AddCheck<MySqlHealthCheck>("MySQL");
// Need to add this line to make it work:
// services.AddSingleton(x => new MySqlHealthCheckOptions(x.GetRequiredService<MySqlDataSource>()));
Anything else we need to know?:
This was probably a regression introduced in #2096; I'll take a look at the code.
Environment:
.NET Core version: 8.0
Healthchecks version: 8.0
Operative system: Windows 10
Others:
The text was updated successfully, but these errors were encountered:
This is a side-effect of the new API design suggested in #2113 (comment).
Following that change, DbHealthCheck no longer has a default constructor and can't be added with .AddCheck<DbHealthCheck>(). Instead, one has to use a new helper extension method, .AddDbHealthCheck().
This is probably best reclassified as a documentation bug: the new extension methods should always be used to add a database health check. (This could affect users upgrading from a previous version, but it is included in a package with a major version number change.)
What happened:
I added a MySQL health check to a simple ASP.NET 8.0 Web API project. When accessing the health check URL I got the following exception:
What you expected to happen:
Expected that URL would return
Healthy
.How to reproduce it (as minimally and precisely as possible):
Source code sample:
Anything else we need to know?:
This was probably a regression introduced in #2096; I'll take a look at the code.
Environment:
The text was updated successfully, but these errors were encountered: