ErrorApi.CSharpFunctionalExtensions
1.0.1
dotnet add package ErrorApi.CSharpFunctionalExtensions --version 1.0.1
NuGet\Install-Package ErrorApi.CSharpFunctionalExtensions -Version 1.0.1
<PackageReference Include="ErrorApi.CSharpFunctionalExtensions" Version="1.0.1" />
<PackageVersion Include="ErrorApi.CSharpFunctionalExtensions" Version="1.0.1" />
<PackageReference Include="ErrorApi.CSharpFunctionalExtensions" />
paket add ErrorApi.CSharpFunctionalExtensions --version 1.0.1
#r "nuget: ErrorApi.CSharpFunctionalExtensions, 1.0.1"
#:package ErrorApi.CSharpFunctionalExtensions@1.0.1
#addin nuget:?package=ErrorApi.CSharpFunctionalExtensions&version=1.0.1
#tool nuget:?package=ErrorApi.CSharpFunctionalExtensions&version=1.0.1

ErrorApi.CSharpFunctionalExtensions
Maps CSharpFunctionalExtensions onto Minimal
API results and ErrorApi's documented error catalog: every endpoint's OpenAPI document lists the
failures it can actually return, and the wire response carries a stable machine-readable code —
resolved at compile time by the ErrorApi source generator, with no reflection at runtime.
dotnet add package ErrorApi.CSharpFunctionalExtensions
The package brings the generator with it (PrivateAssets="none"), so referencing the adapter is the
whole setup.
Before
A Result<T, E> maps to a response at runtime, in a mapper you wrote yourself — and the OpenAPI
document never learns about it:
public Result<Order, OrderError> GetById(Guid id) =>
_orders.TryGetValue(id, out var order) ? order : new OrderNotFound(id);
app.MapGet("/orders/{id:guid}", (Guid id, IOrderService s) =>
s.GetById(id).Match(Results.Ok, e => Results.NotFound())); // hand-rolled, per endpoint
// Document: 200 OK. The 404 exists — the frontend meets it in production.
After
Result<T, E> is the sweet spot for ErrorApi, because the failure already is a type of your own —
that is exactly where the catalog entry goes:
public abstract record OrderError;
[ErrorApi.Error("Orders.NotFound", 404, Title = "Order not found")]
public sealed record OrderNotFound(Guid Id) : OrderError;
public Result<Order, OrderError> GetById(Guid id) =>
_orders.TryGetValue(out var order) ? order : new OrderNotFound(id);
builder.Services.AddErrorApi();
app.MapGet("/orders/{id:guid}", (Guid id, IOrderService s) => s.GetById(id).ToHttpResult());
// Document: 200 + 404 with code "Orders.NotFound", title, and an example body.
// Wire: { "title": "Order not found", "status": 404, "code": "Orders.NotFound" }
The generator documents the endpoint wherever it sees a case constructed; at runtime the instance resolves through a generated pattern switch — no reflection, native-AOT clean.
The whole surface
| shape | success | failure |
|---|---|---|
Result<T, E>.ToHttpResult() |
200 with the value |
ProblemDetails from E |
Result<T, E>.ToCreated(...) / ToCreatedAtUri(...) |
201 |
ProblemDetails |
Result<T, E>.ToNoContentResult() |
204 |
ProblemDetails |
UnitResult<E>.ToHttpResult() |
204 |
ProblemDetails |
Result.ToHttpResult() / Result<T>.ToHttpResult() |
204 / 200 |
see below |
A string-error Result<T> resolves only when the string is a known catalog code; anything else answers
as a 500 carrying the message — deliberately unhelpful as a contract, because a message is not one.
Prefer Result<T, E>.
Versions
Pinned to the CSharpFunctionalExtensions version in this repository's Directory.Packages.props; the
test suite also runs against older releases in CI (-p:CfeTestVersion=x.y.z).
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. 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. |
-
net10.0
- CSharpFunctionalExtensions (>= 3.7.0)
- ErrorApi.AspNetCore (>= 1.0.1)
- Microsoft.AspNetCore.OpenApi (>= 10.0.11)
-
net8.0
- CSharpFunctionalExtensions (>= 3.7.0)
- ErrorApi.AspNetCore (>= 1.0.1)
-
net9.0
- CSharpFunctionalExtensions (>= 3.7.0)
- ErrorApi.AspNetCore (>= 1.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.