Hlibz.Results
3.0.0-preview.2
See the version list below for details.
dotnet add package Hlibz.Results --version 3.0.0-preview.2
NuGet\Install-Package Hlibz.Results -Version 3.0.0-preview.2
<PackageReference Include="Hlibz.Results" Version="3.0.0-preview.2" />
<PackageVersion Include="Hlibz.Results" Version="3.0.0-preview.2" />
<PackageReference Include="Hlibz.Results" />
paket add Hlibz.Results --version 3.0.0-preview.2
#r "nuget: Hlibz.Results, 3.0.0-preview.2"
#:package Hlibz.Results@3.0.0-preview.2
#addin nuget:?package=Hlibz.Results&version=3.0.0-preview.2&prerelease
#tool nuget:?package=Hlibz.Results&version=3.0.0-preview.2&prerelease
![]()
Hlibz.Results
Result, Result<T> and Result<T, TError> for returning expected failures instead of
throwing, with typed errors: each failure is a record carrying the data a client needs, and
an operation declares the errors it returns as a C# 15 union. No dependencies.
dotnet add package Hlibz.Results
using Hlibz.Results;
[Error("cities_1001", ResultStatus.NotFound, "There's no city with this id.")]
public sealed record CityNotFound(Guid CityId) : Error;
[Error("cities_1002", ResultStatus.Conflict, "The city is used by user profiles.")]
public sealed record CityInUse(Guid CityId, int UserCount, IReadOnlyList<Guid> UserIds) : Error;
public union DeleteCityError(CityNotFound, CityInUse);
public Result<Unit, DeleteCityError> Delete(Guid id)
{
if (!_cities.ContainsKey(id))
{
return new CityNotFound(id);
}
Guid[] users = UsersOf(id);
return users.Length > 0 ? new CityInUse(id, users.Length, users) : Unit.Value;
}
string text = service.Delete(id).DeclaredError switch // exhaustive: no _ arm
{
CityNotFound => "No such city.",
CityInUse inUse => $"Used by {inUse.UserCount} profiles.",
null => "Deleted, or an ambient error.",
};
[Error]gives each error type its code, what failed (ResultStatus) and its message.Result<T, TError>fails with an error of its set or an ambient one (ValidationFailed,Unauthorized,Forbidden,ConcurrencyConflict,RateLimited,Unavailable), which the layers around an operation add.Result<T>andResultfail with any error.Map,MapAsyncandBindchain steps, keeping the error set.ErrorCodeCataloglists every error type of the assemblies you give it, plus the ambient ones, sorted by code.
A source generator lists each assembly's error types and error sets as it compiles, so nothing
is scanned at runtime (the package is AOT-compatible), and an analyzer reports as build errors
what would fail at runtime: an error without [Error], two sharing a code, an error returned
where the set doesn't list it.
Hlibz.Results.AspNetCore sends results
as HTTP responses with one error body and documents each declared error per endpoint;
Hlibz.Results.FluentValidation
turns a failed ValidationResult into ValidationFailed;
Hlibz.Results.Mcp fails MCP tools with them.
Targets .NET 11 (C# 15 unions). .NET 10 apps stay on 2.x.
A family of packages
One of five packages I build to set up new .NET APIs the way I want them: Hlibz.Results, Hlibz.UseCases, Hlibz.MinimalApi.Endpoints, Hlibz.OpenApi and Hlibz.Paging. Each works on its own, and they work best together, as in Hlibz.Stack. New minor and major versions come often, a new major whenever .NET gives me a better way to do something. Breaking changes only ever come in a major and are listed first in its release notes. You're welcome to use the packages, and to open an issue when something is wrong or missing.
Full documentation and samples: github.com/hlib-zinchenko/Hlibz.Results.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net11.0 is compatible. |
-
net11.0
- No dependencies.
NuGet packages (4)
Showing the top 4 NuGet packages that depend on Hlibz.Results:
| Package | Downloads |
|---|---|
|
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.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.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.7 | 46 | 12/1/2026 |
| 3.0.0-preview.6 | 50 | 12/1/2026 |
| 3.0.0-preview.5 | 53 | 12/1/2026 |
| 3.0.0-preview.4 | 80 | 11/29/2026 |
| 3.0.0-preview.3 | 155 | 11/27/2026 |
| 3.0.0-preview.2 | 151 | 11/27/2026 |
| 3.0.0-preview.1 | 119 | 11/27/2026 |
| 2.2.0 | 197 | 11/21/2026 |
| 2.2.0-preview.2 | 92 | 11/21/2026 |
| 2.2.0-preview.1 | 75 | 11/21/2026 |
| 2.1.1 | 128 | 11/20/2026 |
| 2.1.0 | 115 | 11/20/2026 |
| 2.0.0 | 143 | 11/18/2026 |
| 2.0.0-preview.4 | 85 | 11/14/2026 |
| 2.0.0-preview.3 | 74 | 11/14/2026 |
| 2.0.0-preview.2 | 78 | 11/13/2026 |
| 2.0.0-preview.1 | 82 | 11/13/2026 |
| 1.1.0 | 151 | 11/12/2026 |
| 1.0.0 | 140 | 11/11/2026 |