ProblemDetails.FluentValidation 1.0.0

dotnet add package ProblemDetails.FluentValidation --version 1.0.0
                    
NuGet\Install-Package ProblemDetails.FluentValidation -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ProblemDetails.FluentValidation" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ProblemDetails.FluentValidation" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="ProblemDetails.FluentValidation" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ProblemDetails.FluentValidation --version 1.0.0
                    
#r "nuget: ProblemDetails.FluentValidation, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ProblemDetails.FluentValidation@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ProblemDetails.FluentValidation&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=ProblemDetails.FluentValidation&version=1.0.0
                    
Install as a Cake Tool

ProblemDetails.FluentValidation

NuGet NuGet Downloads CI License: MIT

RFC 9457 (formerly RFC 7807) application/problem+json error responses for FluentValidation in ASP.NET Core.

Why

When FluentValidation throws a ValidationException, you get a generic 500 error in production. This package converts that into a standard application/problem+json response so your API consumers get structured, machine-readable error details in the same format Microsoft's own ProblemDetails uses.

No manual try-catch blocks or custom middleware to write.

Install

dotnet add package ProblemDetails.FluentValidation

Quick start

Middleware (catches any thrown ValidationException globally)

using ProblemDetails.FluentValidation;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddFluentValidationProblemDetails();
builder.Services.AddScoped<IValidator<Customer>, CustomerValidator>();

var app = builder.Build();

app.UseFluentValidationProblemDetails();

app.MapPost("/customers", (Customer customer) =>
{
    return Results.Ok(customer);
});

app.Run();

When validation fails, the API returns:

{
  "type": "https://httpstatuses.io/422",
  "title": "Unprocessable Entity",
  "status": 422,
  "detail": "One or more validation errors occurred.",
  "instance": "/customers",
  "errors": {
    "Email": ["'Email' is not a valid email address."],
    "Name": ["'Name' must not be empty."]
  }
}

Endpoint filter (per-endpoint control for Minimal APIs)

app.MapPost("/customers", (Customer customer) => { ... })
   .AddEndpointFilter<FluentValidationProblemDetailsFilter>();

Same response shape as the middleware, but only activates on endpoints you choose. Useful when you want validation error handling alongside other endpoint filters.

Configuration

builder.Services.AddFluentValidationProblemDetails(options =>
{
    options.StatusCode = 422;
    options.Type = "https://httpstatuses.io/422";
    options.Title = "Unprocessable Entity";
    options.Detail = "One or more validation errors occurred.";
    options.IncludeTraceId = true;
    options.IncludeRequestId = true;
    options.IncludeValidationErrors = true;

    options.OnProblemDetailsCreated = (problem, httpContext, failures) =>
    {
        problem.Extensions["tenant"] = "acme-corp";
        problem.Extensions["requestId"] = httpContext.TraceIdentifier;
    };
});
Option Default Description
StatusCode 422 HTTP status code returned for validation failures
Type https://httpstatuses.io/422 URI that identifies the problem type
Title "Unprocessable Entity" Short human-readable summary
Detail "One or more validation errors occurred." Human-readable explanation
IncludeTraceId true Adds traceId from Activity.Current or HttpContext.TraceIdentifier
IncludeRequestId true Adds requestId from HttpContext.TraceIdentifier
IncludeValidationErrors true Groups field-level errors by property name under errors
JsonSerializerOptions null Custom System.Text.Json serialization options
Mapper null Replace the default mapper with a custom implementation
OnProblemDetailsCreated null Callback invoked after building the response for custom enrichment

Using IOptions

Options also work with the standard IOptions<T> pattern:

builder.Services.Configure<FluentValidationProblemDetailsOptions>(config =>
{
    config.IncludeTraceId = false;
});

Custom mapper

Replace the entire response shape by implementing IFluentValidationProblemDetailsMapper:

public class CustomMapper : IFluentValidationProblemDetailsMapper
{
    public ProblemDetail Map(
        IEnumerable<ValidationFailure> failures,
        HttpContext httpContext,
        FluentValidationProblemDetailsOptions options)
    {
        // Return any ProblemDetails shape you need
    }
}

builder.Services.AddSingleton<IFluentValidationProblemDetailsMapper, CustomMapper>();

The mapper is resolved from DI first. If you set options.Mapper directly, that takes precedence.

Requirements

  • .NET 8.0 or later
  • FluentValidation 11.x or 12.x

License

MIT

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 166 6/18/2026