Pragmatic.Result 1.0.0-alpha.6

This is a prerelease version of Pragmatic.Result.
dotnet add package Pragmatic.Result --version 1.0.0-alpha.6
                    
NuGet\Install-Package Pragmatic.Result -Version 1.0.0-alpha.6
                    
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="Pragmatic.Result" Version="1.0.0-alpha.6" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Pragmatic.Result" Version="1.0.0-alpha.6" />
                    
Directory.Packages.props
<PackageReference Include="Pragmatic.Result" />
                    
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 Pragmatic.Result --version 1.0.0-alpha.6
                    
#r "nuget: Pragmatic.Result, 1.0.0-alpha.6"
                    
#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 Pragmatic.Result@1.0.0-alpha.6
                    
#: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=Pragmatic.Result&version=1.0.0-alpha.6&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Pragmatic.Result&version=1.0.0-alpha.6&prerelease
                    
Install as a Cake Tool

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>, and Maybe<TValue> are all readonly struct.
  • Multi-error Results: Result<TValue, TError1, …, TError8> and VoidResult<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 on Task<Result>.
  • Collection operators: Combine (fail-fast), CollectAll (accumulate into AggregateError), Partition/GetSuccesses/GetFailures, plus IAsyncEnumerable variants.
  • Exception boundary: Result.Try/Result.TryAsync wrap throwing code; Result.FromNullable and Maybe.ToResult lift nullables into the Result world.
  • Rich error model: Error record base with Code, StatusCode, Title, Parameters, IsTransient/RetryAfter, and WriteExtensions for 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 Result straight 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.AspNetCore ships for net10.0, built on Microsoft.OpenApi 2, and for net11.0, built on Microsoft.OpenApi 3 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-error Result<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 $errorType discriminator. Endpoints need none of this: they unwrap a Result into the value or a ProblemDetails.
  • EF Core integration: SaveChangesAsResultAsync turns DbUpdateException into typed database errors; FirstOrDefaultAsResultAsync/SingleOrDefaultAsResultAsync/FindAsResultAsync return Result instead of null; provider packages parse SQL Server, PostgreSQL, MySQL, and SQLite exceptions into precise error types.
  • Localization-ready: every error carries a stable Code and derived MessageKey; IErrorMessageResolver plugs in custom/localized ProblemDetails messages.
  • Analyzer: PRAG0001 warns when .Value is accessed without checking IsSuccess first.

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 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.

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