MonadicTypes.NET.Errors 0.3.0-preview.2

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

MonadicTypes.NET.Errors

Structured, immutable errors and validation values for MonadicTypes.NET. This package includes MonadicTypes.NET transitively.

Requirements

  • .NET 10 or later
  • Compatible with trimming and NativeAOT
  • No dependency on FluentValidation or another validation framework

Install

dotnet add package MonadicTypes.NET.Errors --prerelease

Quick Start

using MonadicTypes;

public sealed record Customer(int Id);

static Result<Customer, Error> FindCustomer(int id) => id switch
{
    <= 0 => Result<Customer, Error>.Fail(
        Error.Validation("CUSTOMER_ID_INVALID", "Customer ID must be positive.")),
    _ => Result<Customer, Error>.Fail(
        Error.NotFound("CUSTOMER_NOT_FOUND", "The customer does not exist."))
};

ValidationErrors validation = new(
    new ValidationIssue("email", "EMAIL_INVALID", "Email is invalid."));

Error Contract

Error carries a bounded category, stable machine code, message, public-message policy, and optional exception cause. Its focused built-in categories cover validation, authentication, authorization, resource state, request preconditions and content, rate limits, cancellation, upstream failures, and unexpected failures. Construct any built-in category with new Error(type, code, message, ...); the named factories retain the common short forms. Error.Custom supports positive application-defined numeric categories without making the core type itself an HTTP-status catalog.

Error.IO and Error.System provide standard-code convenience forms and custom-code overloads that can retain an exception and explicit disclosure policy without changing their Failure or Unexpected category.

Cause is retained for diagnostics and stack-preserving rethrow; default HTTP conversion never serializes it. Compact domain errors can implement IErrorConvertible<Error> and widen only at an application boundary.

Equality compares category, numeric category, ordinal code, ordinal message, disclosure policy, and retained-cause identity. Hashing uses the same fields. ToString returns [CODE] message; TryFormat writes that representation to a caller-owned span without allocating a string. These contracts do not expose the compact internal message/cause representation.

ValidationErrors.Create maps third-party validation objects through caller supplied functions, so compatibility does not require a runtime dependency on the originating validation library. ValidationErrors is an immutable owner with reference identity; use AsSpan for explicit allocation-free sequence inspection or comparison.

Successful Result<T,Error> paths allocate 0 B. Rich errors allocate only when an error is constructed; use compact readonly domain errors on measured failure hot paths when that allocation matters.

Package Add it for
MonadicTypes.NET.AspNetCore Default HTTP/problem mappings and metadata
MonadicTypes.NET.Diagnostics Activity and Meter projection
MonadicTypes.NET.Effects Mapping thrown exceptions into errors

Documentation

See structured errors and validation and the compatibility contract.

Apache-2.0. Developed with AI assistance.

Complete API reference

Documented public members: 84

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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on MonadicTypes.NET.Errors:

Package Downloads
MonadicTypes.NET.AspNetCore

NativeAOT-compatible typed HTTP results, problem details, validation, and OpenAPI metadata for MonadicTypes.NET.

MonadicTypes.NET.Diagnostics

Optional Activity and Meter instrumentation for structured MonadicTypes.NET errors.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.3.0-preview.2 40 9/12/2026
0.3.0-preview.1 37 9/12/2026
0.2.0-preview.2 97 8/30/2026
0.2.0-preview.1 99 8/17/2026
0.1.0-preview.1 77 8/12/2026