ErrorOrX.Generators 2.4.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package ErrorOrX.Generators --version 2.4.0
                    
NuGet\Install-Package ErrorOrX.Generators -Version 2.4.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="ErrorOrX.Generators" Version="2.4.0">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ErrorOrX.Generators" Version="2.4.0" />
                    
Directory.Packages.props
<PackageReference Include="ErrorOrX.Generators">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
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 ErrorOrX.Generators --version 2.4.0
                    
#r "nuget: ErrorOrX.Generators, 2.4.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 ErrorOrX.Generators@2.4.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=ErrorOrX.Generators&version=2.4.0
                    
Install as a Cake Addin
#tool nuget:?package=ErrorOrX.Generators&version=2.4.0
                    
Install as a Cake Tool

ErrorOrX

NuGet NuGet Downloads License: MIT

Discriminated unions for .NET with source-generated ASP.NET Core Minimal API integration. Zero boilerplate, full AOT support.

Installation

dotnet add package ErrorOrX.Generators

Quick Start

// Program.cs
var app = WebApplication.CreateSlimBuilder(args).Build();
app.MapErrorOrEndpoints();
app.Run();
// TodoApi.cs
using ErrorOr;

public static class TodoApi
{
    [Get("/todos/{id}")]
    public static ErrorOr<Todo> GetById(int id, ITodoService svc)
        => svc.GetById(id) is { } todo
            ? todo
            : Error.NotFound("Todo.NotFound", $"Todo {id} not found");

    [Post("/todos")]
    public static ErrorOr<Todo> Create(CreateTodoRequest req, ITodoService svc)
        => svc.Create(req);  // 201 Created

    [Delete("/todos/{id}")]
    public static ErrorOr<Deleted> Delete(int id, ITodoService svc)
        => svc.Delete(id) ? Result.Deleted : Error.NotFound();
}

Error Types

Factory HTTP Use Case
Error.Validation() 400 Input validation
Error.Unauthorized() 401 Authentication
Error.Forbidden() 403 Authorization
Error.NotFound() 404 Resource not found
Error.Conflict() 409 State conflict
Error.Failure() 500 Operational failure

Fluent API

// Chain operations
var result = ValidateOrder(request)
    .Then(order => ProcessPayment(order))
    .Then(order => CreateShipment(order));

// Handle both cases
return result.Match(
    order => Ok(order),
    errors => BadRequest(errors));

Middleware

[Post("/admin")]
[Authorize("Admin")]
[EnableRateLimiting("fixed")]
public static ErrorOr<User> CreateAdmin(CreateUserRequest req) { }
// Generates: .RequireAuthorization("Admin").RequireRateLimiting("fixed")

Native AOT

Fully compatible with PublishAot=true. The generator produces reflection-free code.

Documentation

License

MIT

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.6.0 28 1/15/2026
2.5.0 34 1/14/2026
2.4.0 40 1/13/2026
2.3.1 38 1/13/2026
2.3.0 35 1/13/2026
2.2.1 41 1/12/2026