Hlibz.Results 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Hlibz.Results --version 1.0.0
                    
NuGet\Install-Package Hlibz.Results -Version 1.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="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Hlibz.Results" Version="1.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 1.0.0
                    
#r "nuget: Hlibz.Results, 1.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@1.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=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Hlibz.Results&version=1.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.

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

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  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.
  • net8.0

    • No dependencies.
  • net9.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