Skip to main content
ErrorOrX provides discriminated union types for .NET with a fluent API for error handling and automatic ASP.NET Core Minimal API integration.

Packages

Installation

ErrorOrX.Generators automatically includes ErrorOrX as a dependency.
v3.0.1+: Fixed automatic PrivateAssets=all issue. No manual .csproj editing required.

What’s New

Performance:
  • Fixed N+1 symbol lookup performance issue. ErrorOrContext is now created once per compilation instead of once per endpoint, reducing symbol lookups from N x 90 to 90 for N endpoints.
API Versioning:
  • Full support for Asp.Versioning.Http with [ApiVersion], [MapToApiVersion], and [ApiVersionNeutral] attributes.
  • New diagnostics EOE050-EOE055 for versioning issues.
New Diagnostics:
  • EOE055: Warning when multiple method parameters bind to the same route parameter name.
Bug Fixes:
  • Fixed NullReferenceException when error type inference encountered local variables.
  • Added null guards on AttributeClass for malformed attributes.
  • Changed route parameter binding to “first wins” semantics for deterministic behavior.

Quick Start

The generator produces:
  • MapErrorOrEndpoints() extension method
  • Typed Results<...> union for OpenAPI
  • Smart parameter binding (infers [FromBody]/[FromServices] based on HTTP method and type)
  • Middleware fluent calls (preserves [Authorize], [EnableRateLimiting], etc.)
  • JSON serialization context (AOT-compatible)

Core Types

ErrorOr<T>

A discriminated union that holds either a value of type T or one or more Error instances.

Fluent API

Or Extensions

Convert nullable values to ErrorOr<T>:

Success Sentinels

For endpoints that don’t return a value: