Fixing ValidationProblemDetails serialization Issues when using the JSON Source Generator in ASP.NET Core
As I gladly accept any kind of performance improvement I can get in my applications, I like to use the System.Text.Json source generator to generate the serialization logic for my Data Transfer Objects. However after upgrading a project to .NET 8, I started to get errors. The problem When using ASP.NET Core's [ApiController] attribute with automatic model validation, the framework automatically returns ValidationProblemDetails objects for validation errors. However, if you've configured your application to use System.Text.Json source generators for performance benefits, you might encounter serialization exceptions like: System.NotSupportedException: JsonTypeInfo metadata for type 'Microsoft.AspNetCore.Mvc.ValidationProblemDetails' was not provided by TypeInfoResolver of type '[]'. If using source generation, ensure that all root types passed to the serializer have been annotated with 'JsonSerializableAttribute', along with any types that might...