Hlibz.Results 2.0.0

dotnet add package Hlibz.Results --version 2.0.0
                    
NuGet\Install-Package Hlibz.Results -Version 2.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Hlibz.Results" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Hlibz.Results" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Hlibz.Results" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Hlibz.Results --version 2.0.0
                    
#r "nuget: Hlibz.Results, 2.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Hlibz.Results@2.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Hlibz.Results&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Hlibz.Results&version=2.0.0
                    
Install as a Cake Tool

Hlibz.Results icon

Hlibz.Results

NuGet CI

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.

Full documentation and samples: github.com/hlib-zinchenko/Hlibz.Results.

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • 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