Skip to content

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.
Namespace SampleApi
Assembly SampleApi
Package v1.0.0.0
public class ProblemDetails
Every 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.
Detail Section titled Detail nullable
string?
string? ProblemDetails.Detail

Gets or sets a human-readable explanation specific to this occurrence of the problem.

IDictionary<string, object?>
IDictionary<string, object?> ProblemDetails.Extensions

Gets the extension members for this problem details instance.

Use this dictionary to include additional context such as trace identifiers, validation errors, or retry-after hints.
Instance Section titled Instance nullable
string?
string? ProblemDetails.Instance

Gets or sets a URI reference that identifies the specific occurrence of the problem.

Status Section titled Status nullable
int?
int? ProblemDetails.Status

Gets or sets the HTTP status code generated by the origin server for this occurrence.

Title Section titled Title nullable
string?
string? ProblemDetails.Title

Gets or sets a short, human-readable summary of the problem type.

Type Section titled Type nullable
string?
string? ProblemDetails.Type

Gets or sets a URI reference that identifies the problem type.

Building 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")
};