AspNetCore.Diagnostics.HealthChecks icon indicating copy to clipboard operation
AspNetCore.Diagnostics.HealthChecks copied to clipboard

NativeAOT support for UiResponseWriter

Open WhatzGames opened this issue 1 year ago • 0 comments

What happened: An exception was thrown: System.InvalidOperationException: Reflection-based serialization has been disabled for this application. Either use the source generator APIs or explicitly configure the 'JsonSerializerOptions.TypeInfoResolver' property.

What you expected to happen: a healthy response json.

How to reproduce it (as minimally and precisely as possible):

  1. Create a NativeAOT WebApi project
  2. Add AspNetCore.HealthChecks.UI.Client
  3. Add the Writer;
  4. I also used AspNetCore.HealthChecks.ApplicationStatus, but I would say It does not matter which ones you use, as the issue lies within the Writer file.
  5. start the application and call the health endpoint.

Source code sample:

using Microsoft.AspNetCore.Diagnostics.HealthChecks;

var builder = WebApplication.CreateSlimBuilder(args);

builder.Services
       .AddHealthChecks()
       .AddApplicationStatus();

builder.Services.AddInfrastructure();

var app = builder.Build();


app.MapHealthChecks("/_health", new HealthCheckOptions {ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse});

await app.RunAsync();

Anything else we need to know?:

Environment:

  • .NET Core version: 8.0.0
  • Healthchecks version: 8.0.0
  • Operative system: Windows 10
  • Others:

WhatzGames avatar Jan 26 '24 14:01 WhatzGames