ramonsmits / Extensions.Hosting.Systemd.Watchdog

Systemd watchdog implementation for Microsoft.Extensions.Hosting.Systemd
0 stars 1 forks source link

Stackoverflow in web API project #1

Open MilanLochovsky opened 2 months ago

MilanLochovsky commented 2 months ago

Hello,

thanks for library. But if i use it in simple new "Web API" project, then fail on start with 'Stack overflow' exception.

using System.Text.Json.Serialization;

var builder = WebApplication.CreateSlimBuilder(args);

builder.UseSystemd(enableWatchdog: true);

builder.Services.ConfigureHttpJsonOptions(options =>
{
    options.SerializerOptions.TypeInfoResolverChain.Insert(0, AppJsonSerializerContext.Default);
});

var app = builder.Build();

var sampleTodos = new Todo[]
{
    new(1, "Walk the dog"),
    new(2, "Do the dishes", DateOnly.FromDateTime(DateTime.Now)),
    new(3, "Do the laundry", DateOnly.FromDateTime(DateTime.Now.AddDays(1))),
    new(4, "Clean the bathroom"),
    new(5, "Clean the car", DateOnly.FromDateTime(DateTime.Now.AddDays(2)))
};

var todosApi = app.MapGroup("/todos");
todosApi.MapGet("/", () => sampleTodos);
todosApi.MapGet("/{id}", (int id) =>
    sampleTodos.FirstOrDefault(a => a.Id == id) is { } todo
        ? Results.Ok(todo)
        : Results.NotFound());

app.Run();

public record Todo(int Id, string? Title, DateOnly? DueBy = null, bool IsComplete = false);

[JsonSerializable(typeof(Todo[]))]
internal partial class AppJsonSerializerContext : JsonSerializerContext
{
}
Stack overflow.
Repeat 19272 times:
--------------------------------
   at Microsoft.Extensions.Hosting.WatchdogHostBuilderExtensions.UseSystemd(Microsoft.Extensions.Hosting.IHostApplicationBuilder, Boolean)
--------------------------------
   at Program.<Main>$(System.String[])
ramonsmits commented 1 month ago

That is strange, maybe I didn't push the correct commit. Thanks for reporting!