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.
Definition
Section titled Definitionpublic record ValidationError : System.IEquatable<SampleApi.ValidationError> IEquatable<ValidationError>
Inheritance
Section titled Inheritance IEquatable<ValidationError>
classDiagram
direction TB
class ValidationError {
<<record>>
}
class IEquatable~ValidationError~ {
<<interface>>
}
IEquatable~ValidationError~ <|.. ValidationErrorRemarks
Section titled RemarksValidation 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.
Constructors1
Section titled ConstructorsConstructor Section titled Constructor 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.
Parameters
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. Remarks
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.
Examples
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")};Properties3
Section titled Propertiesstring? string? ValidationError.CodeAn 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.
Field Section titled Field string string ValidationError.FieldThe name of the input field that failed validation, using the same casing as the JSON property name (e.g., "email", "fullName").
Message Section titled Message string string ValidationError.MessageA human-readable, locale-sensitive message describing why the field value is invalid (e.g., "Email address is not in a valid format.").
Examples
Section titled ExamplesCreating 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")};