ProblemDetails
Class public
A machine-readable error response body following the RFC 9457 (Problem Details for HTTP APIs) specification, providing a standardized structure that clients can parse without knowledge of the specific API.
Definition
Section titled Definitionpublic class ProblemDetailsRemarks
Section titled RemarksEvery field in ProblemDetails is optional. At minimum, set
Status and Title. Use Type to point to a documentation page describing the error category. The Extensions dictionary allows attaching arbitrary additional context—common patterns include:- A
"traceId"for correlating with server logs. - A
"errors"array of ValidationError for 400 responses. - A
"retryAfter"value for 429 / 503 responses.
Properties6
Section titled Propertiesstring? string? ProblemDetails.DetailGets or sets a human-readable explanation specific to this occurrence of the problem.
Extensions Section titled Extensions IDictionary<string, object?> IDictionary<string, object?> ProblemDetails.ExtensionsGets the extension members for this problem details instance.
Remarks
Use this dictionary to include additional context such as trace identifiers, validation errors, or retry-after hints.
string? string? ProblemDetails.InstanceGets or sets a URI reference that identifies the specific occurrence of the problem.
int? int? ProblemDetails.StatusGets or sets the HTTP status code generated by the origin server for this occurrence.
string? string? ProblemDetails.TitleGets or sets a short, human-readable summary of the problem type.
string? string? ProblemDetails.TypeGets or sets a URI reference that identifies the problem type.
Examples
Section titled ExamplesBuilding a 404 problem details response:
var problem = new ProblemDetails{ Type = "https://api.example.com/errors/not-found", Title = "Customer Not Found", Status = 404, Detail = $"No customer with ID '{id}' exists.", Instance = $"/api/v1/customers/{id}"};problem.Extensions["traceId"] = Activity.Current?.Id;Building a 400 validation problem details:
var problem = new ProblemDetails{ Type = "https://api.example.com/errors/validation", Title = "Validation Failed", Status = 400, Detail = "One or more fields failed validation."};problem.Extensions["errors"] = new[]{ new ValidationError("email", "Invalid email format.", "INVALID_FORMAT")};