CSharpEssentials.Errors
3.0.5
dotnet add package CSharpEssentials.Errors --version 3.0.5
NuGet\Install-Package CSharpEssentials.Errors -Version 3.0.5
<PackageReference Include="CSharpEssentials.Errors" Version="3.0.5" />
<PackageVersion Include="CSharpEssentials.Errors" Version="3.0.5" />
<PackageReference Include="CSharpEssentials.Errors" />
paket add CSharpEssentials.Errors --version 3.0.5
#r "nuget: CSharpEssentials.Errors, 3.0.5"
#:package CSharpEssentials.Errors@3.0.5
#addin nuget:?package=CSharpEssentials.Errors&version=3.0.5
#tool nuget:?package=CSharpEssentials.Errors&version=3.0.5
CSharpEssentials.Errors
Structured, type-safe error handling for .NET. Errors are data, not exceptions.
Features
- Error Struct — Value-type error with code, description, type, and metadata.
- Standard Error Types — Failure, Validation, NotFound, Conflict, Unauthorized, Forbidden, Unexpected.
- ErrorMetadata — Attach contextual data to errors fluently.
- Exception Bridge — Convert exceptions to
Erroror throwDomainException/EnhancedValidationException. - HTTP Mapping — Built-in conversion between
ErrorTypeand HTTP status codes.
Installation
dotnet add package CSharpEssentials.Errors
Usage
Creating Errors
using CSharpEssentials.Errors;
Error notFound = Error.NotFound("User.NotFound", "User was not found.");
Error validation = Error.Validation("Email.Invalid", "Email format is invalid.");
Error conflict = Error.Conflict("User.Duplicate", "User already exists.");
Error failure = Error.Failure("Payment.Failed", "Payment was rejected.");
Error Metadata
Error withMeta = Error.NotFound(
"User.NotFound",
"User was not found.",
new ErrorMetadata()
.AddMetadata("TraceId", Guid.NewGuid().ToString())
.AddMetadata("RequestPath", "/api/users/123"));
Combining Errors
Error a = Error.Validation("Name.Empty", "Name is required.");
Error b = Error.Validation("Email.Invalid", "Email is invalid.");
Error[] combined = a + b;
Converting from Exceptions
try { /* ... */ }
catch (Exception ex)
{
Error error = Error.Exception(ex);
}
Domain Exceptions
using CSharpEssentials.Exceptions;
Error error = Error.Validation("Order.Invalid", "Total must be greater than zero.");
throw new DomainException(error);
HTTP Status Mapping
int status = ErrorType.NotFound.ToHttpStatusCode(); // 404
ErrorType type = 401.ToErrorType(); // Unauthorized
Domain-Specific Error Hierarchies
Error is a value type (readonly record struct) and cannot be subclassed. The idiomatic way to build domain-specific, typed error hierarchies is to group static factory methods in a dedicated class per aggregate or bounded context:
using CSharpEssentials.Errors;
// Organize errors by domain aggregate
public static class UserErrors
{
public static Error NotFound(Guid id) =>
Error.NotFound("User.NotFound", $"User '{id}' was not found.");
public static readonly Error AlreadyExists =
Error.Conflict("User.AlreadyExists", "A user with that email already exists.");
public static Error InvalidAge(int age) =>
Error.Validation("User.InvalidAge", $"Age {age} is not allowed; must be 18 or older.");
public static readonly Error Unauthorized =
Error.Unauthorized("User.Unauthorized", "You are not authorized to perform this action.");
}
public static class OrderErrors
{
public static readonly Error EmptyCart =
Error.Validation("Order.EmptyCart", "Cannot place an order with an empty cart.");
public static Error InsufficientFunds(decimal required, decimal available) =>
Error.Failure(
"Order.InsufficientFunds",
$"Payment requires {required:C} but only {available:C} is available.",
new ErrorMetadata().AddMetadata("Required", required).AddMetadata("Available", available));
}
Usage with Result:
using CSharpEssentials.ResultPattern;
public Result<User> FindUser(Guid id)
{
User? user = _repo.Find(id);
if (user is null)
return UserErrors.NotFound(id); // implicit Error → Result<User>
return user;
}
public Result PlaceOrder(Cart cart, decimal balance)
{
if (cart.IsEmpty)
return OrderErrors.EmptyCart;
if (balance < cart.Total)
return OrderErrors.InsufficientFunds(cart.Total, balance);
return Result.Success();
}
This pattern provides discoverability (IDE autocomplete per domain), type-safe error codes, and centralised descriptions — without inheritance.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. net11.0 is compatible. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- CSharpEssentials.Core (>= 3.0.5)
- CSharpEssentials.Enums (>= 3.0.5)
- System.Text.Json (>= 9.0.4)
-
net10.0
- CSharpEssentials.Core (>= 3.0.5)
- CSharpEssentials.Enums (>= 3.0.5)
-
net11.0
- CSharpEssentials.Core (>= 3.0.5)
- CSharpEssentials.Enums (>= 3.0.5)
-
net9.0
- CSharpEssentials.Core (>= 3.0.5)
- CSharpEssentials.Enums (>= 3.0.5)
NuGet packages (6)
Showing the top 5 NuGet packages that depend on CSharpEssentials.Errors:
| Package | Downloads |
|---|---|
|
CSharpEssentials
A comprehensive C# library enhancing functional programming capabilities with type-safe monads (Maybe, Result), discriminated unions (Any), and robust error handling. Features include: domain-driven design support, enhanced Entity Framework integration, testable time management, JSON utilities, and LINQ extensions. Built for modern C# development with focus on maintainability, testability, and functional programming principles. |
|
|
CSharpEssentials.AspNetCore
A comprehensive ASP.NET Core library that enhances functional programming capabilities in web applications. Features include API versioning, global exception handling with enhanced problem details, advanced Swagger/OpenAPI configuration, model validation, optimized JSON handling, and seamless integration with CSharpEssentials core functional patterns (Result, Maybe, Rule Engine). Perfect for building robust, maintainable, and type-safe web APIs following functional programming principles. |
|
|
CSharpEssentials.Results
Result pattern implementation for functional error handling in C#. Provides Result<T> and Result types for railway-oriented programming, eliminating exceptions for expected failures. Foundation for functional programming patterns and robust error handling. |
|
|
CSharpEssentials.Maybe
Maybe monad implementation with LINQ support for functional programming in C#. Provides type-safe null handling, eliminates null reference exceptions, and enables functional composition. Essential for functional programming patterns and safe value handling. |
|
|
CSharpEssentials.Http
HttpClient extensions that bridge HTTP calls to the Result pattern. Provides GetFromJsonAsResultAsync, PostAsJsonAsResultAsync, status code mapping, and Polly resilience integration. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 3.0.5 | 30 | 5/7/2026 |
| 3.0.4 | 133 | 5/6/2026 |
| 3.0.3 | 182 | 5/5/2026 |
| 3.0.2 | 232 | 5/5/2026 |
| 3.0.1 | 315 | 5/3/2026 |
| 3.0.0 | 297 | 5/3/2026 |
| 2.1.0 | 376 | 11/26/2025 |
| 2.0.9 | 315 | 9/30/2025 |
| 2.0.8 | 304 | 9/29/2025 |
| 2.0.7 | 292 | 9/29/2025 |
| 2.0.6 | 316 | 9/29/2025 |
| 2.0.5 | 302 | 9/29/2025 |
| 2.0.4 | 326 | 9/28/2025 |
| 2.0.3 | 308 | 9/28/2025 |
| 2.0.2 | 308 | 9/28/2025 |
| 2.0.1 | 316 | 9/28/2025 |
| 2.0.0 | 313 | 9/28/2025 |