Packages
| Package | Purpose |
|---|---|
ErrorOrX | Runtime library with ErrorOr<T> type |
ErrorOrX.Generators | Source generator for Minimal API endpoints |
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
Recent Changes (v3.1+)
Recent Changes (v3.1+)
Performance:
- Fixed N+1 symbol lookup performance issue.
ErrorOrContextis now created once per compilation instead of once per endpoint, reducing symbol lookups from N x 90 to 90 for N endpoints.
- Full support for
Asp.Versioning.Httpwith[ApiVersion],[MapToApiVersion], and[ApiVersionNeutral]attributes. - New diagnostics EOE050-EOE055 for versioning issues.
- EOE055: Warning when multiple method parameters bind to the same route parameter name.
- Fixed
NullReferenceExceptionwhen error type inference encountered local variables. - Added null guards on
AttributeClassfor malformed attributes. - Changed route parameter binding to “first wins” semantics for deterministic behavior.
Quick Start
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 typeT or one or more Error instances.
Fluent API
| Method | Purpose |
|---|---|
Then() | Chain operations on success |
Else() | Provide fallback on error |
Match() | Transform to result |
Switch() | Execute side effects |
FailIf() | Conditional failure |
Or Extensions
Convert nullable values toErrorOr<T>:
Success Sentinels
For endpoints that don’t return a value:| Sentinel | HTTP Status | TypedResult |
|---|---|---|
Result.Success | 200 | Ok |
Result.Created | 201 | Created |
Result.Updated | 200 | Ok |
Result.Deleted | 204 | NoContent |
