Hlibz.Results
2.2.0
See the version list below for details.
dotnet add package Hlibz.Results --version 2.2.0
NuGet\Install-Package Hlibz.Results -Version 2.2.0
<PackageReference Include="Hlibz.Results" Version="2.2.0" />
<PackageVersion Include="Hlibz.Results" Version="2.2.0" />
<PackageReference Include="Hlibz.Results" />
paket add Hlibz.Results --version 2.2.0
#r "nuget: Hlibz.Results, 2.2.0"
#:package Hlibz.Results@2.2.0
#addin nuget:?package=Hlibz.Results&version=2.2.0
#tool nuget:?package=Hlibz.Results&version=2.2.0
![]()
Hlibz.Results
A small Result / Result<T> for returning expected failures instead of throwing: a status,
a message, a machine-readable error code and validation errors. No dependencies.
dotnet add package Hlibz.Results
using Hlibz.Results;
public sealed record OrdersErrorCode(string Code, string Message)
: ErrorCode($"orders_{Code}", Message);
public static class OrdersErrorCodes
{
public static readonly ErrorCode OrderClosed =
new OrdersErrorCode("1001", "The order is closed.");
}
public async Task<Result<OrderDto>> AddLineAsync(Guid orderId, AddLine line)
{
Order? order = await _orders.GetAsync(orderId);
if (order is null)
{
return Result<OrderDto>.NotFound();
}
if (order.IsClosed)
{
return Result<OrderDto>.Conflict(OrdersErrorCodes.OrderClosed);
}
Result added = order.AddLine(line);
if (added.IsFailure)
{
return Result<OrderDto>.FromFailed(added);
}
return Result<OrderDto>.Success(order.ToDto());
}
| Status | Factory |
|---|---|
Success |
Success() / Success(value) |
Error |
Error(message), Error(errorCode), Error(validationErrors) |
Invalid |
Invalid(validationErrors) |
NotFound |
NotFound(message?), NotFound(errorCode) |
Unauthorized |
Unauthorized(message?), Unauthorized(errorCode) |
Forbidden |
Forbidden(message?), Forbidden(errorCode) |
Conflict |
Conflict(message?), Conflict(errorCode) |
Unavailable |
Unavailable(message?), Unavailable(errorCode) |
Error is a broken business rule or another bad request, Invalid a failed input validation;
validation errors can ride on either, so an API that doesn't tell them apart can use Error
only. Result<T> is a Result, and IsSuccess tells the compiler Value isn't null.
FromFailed passes a failure on as another type; Map, MapAsync and Bind chain steps.
ErrorCodeCatalog collects every public static ErrorCode declared in the assemblies you give
it, sorted, and throws when two share a code. The package's source generator lists each
assembly's codes as it compiles, so nothing is scanned at runtime; the package is AOT-compatible.
Related packages
- Hlibz.Results.AspNetCore: results to HTTP responses with one error body, for minimal APIs and controllers.
- Hlibz.Results.FluentValidation:
a failed
ValidationResultto a failure. - Hlibz.Paging: paging and sorting; a bad sort
string becomes
Result.Invalid.
Full documentation and samples: github.com/hlib-zinchenko/Hlibz.Results.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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. net11.0 is compatible. |
-
net10.0
- No dependencies.
-
net11.0
- No dependencies.
NuGet packages (4)
Showing the top 4 NuGet packages that depend on Hlibz.Results:
| Package | Downloads |
|---|---|
|
Hlibz.Results.AspNetCore
Turns Hlibz.Results into HTTP responses with one error body everywhere: result.ToHttpResult() for minimal APIs (or a plain Result returned from a handler with WithResultResponses()) and result.ToActionResult() for controllers map Success/Error/Invalid/NotFound/Unauthorized/Forbidden/Conflict/Unavailable to 200/400/400/404/401/403/409/503 (remappable, e.g. 422 for validation), with { message, code, validation_errors } on every failure, the authorization gate's own 401/403 included. Optional Crunch-style envelope ({ data, is_success, status, message, code, validation_errors }), WithResultEnvelopes() for handlers returning a plain Result, validation keys cased by your JSON naming policy per path segment, and an error code catalog endpoint listing every code your API returns. |
|
|
Hlibz.Results.FluentValidation
Turns a failed FluentValidation ValidationResult into a Hlibz.Results ValidationFailed error carrying its validation errors, grouped by property path: return validationResult.ToValidationFailed(); converts to any result. Works with FluentValidation 11.0.0 and later. |
|
|
Hlibz.UseCases
Use cases for .NET apps with several clients (HTTP endpoints, MCP tools, gRPC services, jobs): a record implementing IUseCase, a handler implementing IUseCaseHandler<TUseCase, TResult, TError> and returning Hlibz.Results' Result<TResult, TError> (the value, or one of the errors it declares, a C# union of error types), and every client injecting the handler's own interface. A source generator lists the handlers at compile time (no assembly scan) and wraps each one in a pipeline that validates the use case against its DataAnnotations first, the same rules ASP.NET Core's validation applies (nested records, collections, record parameter attributes, IValidatableObject), with no ASP.NET Core dependency, then runs your own filters. Custom validation attributes can describe themselves (IDescribedRule, [RuleSummary]) for OpenAPI or tool schemas to publish. |
|
|
Hlibz.Results.Mcp
Turns Hlibz.Results errors into MCP tool errors a model can act on: a tool unwraps its result with ValueOrThrow(), and a failed call comes back as isError with guidance (what to do next, in terms of your tools, its {placeholders} filled from the error's data) as text, and { code, details } as structured content. Each tool lists the errors it can return, declared with [ToolErrors<TErrorSet>] or worked out by your own IToolErrorSource, in its _meta under "hlibz/errors", which Hlibz.McpDocs.AspNetCore shows on its docs page. The server doesn't start while a tool's error has no guidance. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 3.0.0-preview.3 | 0 | 11/27/2026 |
| 3.0.0-preview.2 | 0 | 11/27/2026 |
| 3.0.0-preview.1 | 0 | 11/27/2026 |
| 2.2.0 | 175 | 11/21/2026 |
| 2.2.0-preview.2 | 83 | 11/21/2026 |
| 2.2.0-preview.1 | 68 | 11/21/2026 |
| 2.1.1 | 120 | 11/20/2026 |
| 2.1.0 | 109 | 11/20/2026 |
| 2.0.0 | 133 | 11/18/2026 |
| 2.0.0-preview.4 | 79 | 11/14/2026 |
| 2.0.0-preview.3 | 71 | 11/14/2026 |
| 2.0.0-preview.2 | 73 | 11/13/2026 |
| 2.0.0-preview.1 | 75 | 11/13/2026 |
| 1.1.0 | 143 | 11/12/2026 |
| 1.0.0 | 134 | 11/11/2026 |