Pragmatic.Result
1.0.0-alpha.6
dotnet add package Pragmatic.Result --version 1.0.0-alpha.6
NuGet\Install-Package Pragmatic.Result -Version 1.0.0-alpha.6
<PackageReference Include="Pragmatic.Result" Version="1.0.0-alpha.6" />
<PackageVersion Include="Pragmatic.Result" Version="1.0.0-alpha.6" />
<PackageReference Include="Pragmatic.Result" />
paket add Pragmatic.Result --version 1.0.0-alpha.6
#r "nuget: Pragmatic.Result, 1.0.0-alpha.6"
#:package Pragmatic.Result@1.0.0-alpha.6
#addin nuget:?package=Pragmatic.Result&version=1.0.0-alpha.6&prerelease
#tool nuget:?package=Pragmatic.Result&version=1.0.0-alpha.6&prerelease
Pragmatic.Result
Zero-allocation Result types for .NET 10 with railway-oriented programming.
The Problem
Most .NET code signals failure by throwing. That hides error paths from method signatures, forces
callers to guess what to catch, and allocates expensive stack traces for expected outcomes like
"entity not found". The compiler can't enforce handling: miss a catch and you ship a generic 500.
// Without Pragmatic.Result: error paths are invisible, exceptions are expensive
public async Task<User> GetUserAsync(int id)
{
var user = await _repository.FindByIdAsync(id);
if (user is null) throw new NotFoundException($"User {id} not found"); // hidden, expensive
if (!user.IsActive) throw new BusinessRuleException("User is inactive"); // hidden, expensive
return user;
}
The Solution
Make error paths explicit in the type system. Return Result<TValue, TError> instead of throwing:
the compiler ensures callers handle both outcomes. The wrapper itself is zero-allocation.
public async Task<Result<User, NotFoundError>> GetUserAsync(int id)
{
var user = await _repository.FindByIdAsync(id);
if (user is null) return NotFoundError.Create("User", id); // implicit conversion to failure
return user; // implicit conversion to success
}
// Caller: exhaustive, compiler-enforced
var message = result.Match(
user => $"Found: {user.Name}",
error => $"Not found: {error.EntityId}");
Features
- Zero-allocation core:
Result<TValue, TError>,Result<TValue>,VoidResult,VoidResult<TError>, andMaybe<TValue>are allreadonly struct. - Multi-error Results:
Result<TValue, TError1, …, TError8>andVoidResult<TError1, …, TError8>variants for up to 8 typed errors per operation, shipped pre-generated in the package. - Railway-oriented composition:
Map,Bind,Match,Tap,Ensure,Recover,OrElse, each with async counterparts (MapAsync,BindAsync,MatchAsync, …) that chain onTask<Result>. - Collection operators:
Combine(fail-fast),CollectAll(accumulate intoAggregateError),Partition/GetSuccesses/GetFailures, plusIAsyncEnumerablevariants. - Exception boundary:
Result.Try/Result.TryAsyncwrap throwing code;Result.FromNullableandMaybe.ToResultlift nullables into the Result world. - Rich error model:
Errorrecord base withCode,StatusCode,Title,Parameters,IsTransient/RetryAfter, andWriteExtensionsfor structured ProblemDetails payloads. - 8 built-in HTTP error types:
BadRequestError(400),UnauthorizedError(401),ForbiddenError(403),NotFoundError(404),ConflictError(409),BusinessRuleError(422),InternalServerError(500),DependencyError(502/503/504), each with factory methods. - ASP.NET Core integration: return
Resultstraight from Minimal API endpoints (WithResultHandling()) or Controllers (ResultActionFilter); failures become RFC 7807 ProblemDetails with the right status code; OpenAPI transformers document Result schemas and error responses (AddResultTypeSupport()).Pragmatic.Result.AspNetCoreships for net10.0, built onMicrosoft.OpenApi2, and for net11.0, built onMicrosoft.OpenApi3 as ASP.NET Core 11 requires. The public API is the same on both. - JSON round-trip: typed, AOT-safe converters you register for the shapes you serialize
(
ResultJsonConverter<TValue, TError>,VoidResultJsonConverter<TError>,MaybeJsonConverter<T>); a multi-errorResult<T, E1, E2, …>is declared with[assembly: JsonResultContract<…>]and the generator writes its converter. There is no open-generic factory. The concrete error type travels in the$errorTypediscriminator. Endpoints need none of this: they unwrap aResultinto the value or a ProblemDetails. - EF Core integration:
SaveChangesAsResultAsyncturnsDbUpdateExceptioninto typed database errors;FirstOrDefaultAsResultAsync/SingleOrDefaultAsResultAsync/FindAsResultAsyncreturnResultinstead of null; provider packages parse SQL Server, PostgreSQL, MySQL, and SQLite exceptions into precise error types. - Localization-ready: every error carries a stable
Codeand derivedMessageKey;IErrorMessageResolverplugs in custom/localized ProblemDetails messages. - Analyzer:
PRAG0001warns when.Valueis accessed without checkingIsSuccessfirst.
Packages
| Package | Description |
|---|---|
Pragmatic.Result |
Core Result/VoidResult/Maybe types, error model, HTTP errors, JSON converters |
Pragmatic.Result.AspNetCore |
ProblemDetails, Minimal API & Controller filters, OpenAPI transformers |
Pragmatic.Result.EFCore |
SaveChangesAsResultAsync, query extensions, database error types |
Pragmatic.Result.EFCore.SqlServer |
SQL Server exception parser |
Pragmatic.Result.EFCore.PostgreSQL |
PostgreSQL exception parser |
Pragmatic.Result.EFCore.MySql |
MySQL exception parser |
Pragmatic.Result.EFCore.Sqlite |
SQLite exception parser |
Pragmatic.Result.Analyzers |
PRAG0001 unsafe .Value access analyzer |
Installation
dotnet add package Pragmatic.Result
dotnet add package Pragmatic.Result.AspNetCore # optional: ASP.NET Core integration
dotnet add package Pragmatic.Result.EFCore # optional: EF Core integration
Quick Start
using Pragmatic.Result;
using Pragmatic.Result.Http;
Result<User, NotFoundError> result = user; // success (implicit)
Result<User, NotFoundError> failed = NotFoundError.Create("User", userId);
var output = result.Match(
user => $"Found: {user.Name}",
error => $"Error: {error.EntityType} not found");
if (result.TryGetValue(out var value))
Console.WriteLine(value.Name);
In ASP.NET Core, return Result types straight from endpoints and let the integration map them to
HTTP: success to 200, typed errors to the right status + an RFC 7807 ProblemDetails:
builder.Services.AddPragmaticResult();
var api = app.MapGroup("").WithResultHandling();
api.MapGet("/users/{id}", (int id, UserService svc) => svc.GetByIdAsync(id));
// Result<User, NotFoundError> → 200 with JSON, or 404 ProblemDetails
Full walkthrough: Getting Started.
Status
Stable within 1.0.0-alpha: the core Result API, error types, and the ASP.NET Core and EF Core
integrations are settled. See the roadmap.
Documentation
| Guide | What you'll learn |
|---|---|
| Concepts | Railway-oriented model, when Result beats exceptions, decision guide |
| Getting Started | Your first Result, matching, ASP.NET Core wiring |
| API Reference | Every extension (Map/Bind/Match/Tap/Ensure), error types, ProblemDetails, JSON, OpenAPI |
| Localization | IErrorMessageResolver, localized error messages |
| Migration | Moving from exceptions / other Result libraries |
| Common Mistakes | The most frequent Result pitfalls |
| Troubleshooting | Problem/solution guide |
Requirements
- .NET 10.0+
License
Part of the Pragmatic.Design ecosystem. See Licensing. Pragmatic.Result is MIT-licensed.
| 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
- Pragmatic.Abstractions (>= 1.0.0-alpha.6)
- Pragmatic.Internationalization (>= 1.0.0-alpha.6)
-
net11.0
- Pragmatic.Abstractions (>= 1.0.0-alpha.6)
- Pragmatic.Internationalization (>= 1.0.0-alpha.6)
NuGet packages (14)
Showing the top 5 NuGet packages that depend on Pragmatic.Result:
| Package | Downloads |
|---|---|
|
Pragmatic.Caching
Source-generated caching with typed keys, automatic invalidation, and HybridCache integration. Zero magic strings. |
|
|
Pragmatic.Validation
Source-generated validation with zero reflection. Compile-time attribute validation, async validators, Result pattern integration. |
|
|
Pragmatic.Actions
DomainAction pattern with Pipeline, Filters, and Boundary support. Zero reflection, compile-time safe, source-generated. |
|
|
Pragmatic.Persistence
Persistence abstractions for Pragmatic.Design - Entity definitions, Repository pattern, UnitOfWork, and DTO-driven Query/Mutation patterns. Database-agnostic, works with any ORM. |
|
|
Pragmatic.Resilience
Native resilience library: retry, timeout, circuit breaker, bulkhead, fallback, hedging, rate limiter. AOT-safe, SG-driven. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0-alpha.6 | 503 | 11/21/2026 |
| 1.0.0-alpha.5 | 443 | 11/21/2026 |
| 1.0.0-alpha.4 | 473 | 11/16/2026 |
| 1.0.0-alpha.3 | 768 | 10/17/2026 |
| 1.0.0-alpha.2 | 376 | 10/12/2026 |
| 1.0.0-alpha.1 | 599 | 10/3/2026 |