Skip to content

ValidationError

Record public
Describes a single validation error tied to a specific input field, including a human-readable message and an optional machine-readable error code.
Namespace SampleApi
Assembly SampleApi
Package v1.0.0.0
public record ValidationError
: System.IEquatable<SampleApi.ValidationError>
IEquatable<ValidationError>
Implements
IEquatable<ValidationError>
classDiagram
    direction TB
    class ValidationError {
        <<record>>
    }
    class IEquatable~ValidationError~ {
        <<interface>>
    }
    IEquatable~ValidationError~ <|.. ValidationError
Validation errors are typically collected during request processing and surfaced to the client as an array within a ProblemDetails response. Use consistent error codes across the API to allow clients to build locale-aware error displays.
ValidationError.ValidationError(
string Field,
string Message,
string? Code = null)

Describes a single validation error tied to a specific input field, including a human-readable message and an optional machine-readable error code.

Field string
The name of the input field that failed validation, using the same casing as the JSON property name (e.g., "email", "fullName").
Message string
A human-readable, locale-sensitive message describing why the field value is invalid (e.g., "Email address is not in a valid format.").
Code string? optional
An application-specific error code for programmatic handling, such as "INVALID_FORMAT" or "FIELD_REQUIRED". When null, the client should rely on the Message for context.
Validation errors are typically collected during request processing and surfaced to the client as an array within a ProblemDetails response. Use consistent error codes across the API to allow clients to build locale-aware error displays.

Creating a list of validation errors:

var errors = new List<ValidationError>
{
new("email", "Email address is required.", "FIELD_REQUIRED"),
new("fullName", "Full name must be between 1 and 200 characters.", "INVALID_LENGTH")
};
Code Section titled Code nullable
string?
string? ValidationError.Code

An application-specific error code for programmatic handling, such as "INVALID_FORMAT" or "FIELD_REQUIRED". When null, the client should rely on the Message for context.

string ValidationError.Field

The name of the input field that failed validation, using the same casing as the JSON property name (e.g., "email", "fullName").

string ValidationError.Message

A human-readable, locale-sensitive message describing why the field value is invalid (e.g., "Email address is not in a valid format.").

Creating a list of validation errors:

var errors = new List<ValidationError>
{
new("email", "Email address is required.", "FIELD_REQUIRED"),
new("fullName", "Full name must be between 1 and 200 characters.", "INVALID_LENGTH")
};