Hlibz.Results
2.0.0
dotnet add package Hlibz.Results --version 2.0.0
NuGet\Install-Package Hlibz.Results -Version 2.0.0
<PackageReference Include="Hlibz.Results" Version="2.0.0" />
<PackageVersion Include="Hlibz.Results" Version="2.0.0" />
<PackageReference Include="Hlibz.Results" />
paket add Hlibz.Results --version 2.0.0
#r "nuget: Hlibz.Results, 2.0.0"
#:package Hlibz.Results@2.0.0
#addin nuget:?package=Hlibz.Results&version=2.0.0
#tool nuget:?package=Hlibz.Results&version=2.0.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 (2)
Showing the top 2 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 failure carrying its validation errors, grouped by property path, with the status your API wants: validationResult.ToErrorResult() or validationResult.ToInvalidResult(). Works with FluentValidation 11.0.0 and later. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.0.0 | 90 | 11/18/2026 |
| 2.0.0-preview.4 | 73 | 11/14/2026 |
| 2.0.0-preview.3 | 65 | 11/14/2026 |
| 2.0.0-preview.2 | 68 | 11/13/2026 |
| 2.0.0-preview.1 | 68 | 11/13/2026 |
| 1.1.0 | 139 | 11/12/2026 |
| 1.0.0 | 131 | 11/11/2026 |