CSharpEssentials.Errors
3.0.2
See the version list below for details.
dotnet add package CSharpEssentials.Errors --version 3.0.2
NuGet\Install-Package CSharpEssentials.Errors -Version 3.0.2
<PackageReference Include="CSharpEssentials.Errors" Version="3.0.2" />
<PackageVersion Include="CSharpEssentials.Errors" Version="3.0.2" />
<PackageReference Include="CSharpEssentials.Errors" />
paket add CSharpEssentials.Errors --version 3.0.2
#r "nuget: CSharpEssentials.Errors, 3.0.2"
#:package CSharpEssentials.Errors@3.0.2
#addin nuget:?package=CSharpEssentials.Errors&version=3.0.2
#tool nuget:?package=CSharpEssentials.Errors&version=3.0.2
CSharpEssentials.Errors
CSharpEssentials.Errors provides a structured, type-safe error handling system for .NET applications. It encapsulates errors as data rather than exceptions, promoting the Result pattern and making failure flows explicit and manageable.
🚀 Features
- Structured Errors:
Errorstruct with unique codes, descriptions, and types (NotFound, Validation, Conflict, etc.). - Rich Metadata: Attach additional context (
ErrorMetadata) to errors. - Standard Error Types: predefined types like
Failure,Unexpected,Validation,Conflict,NotFound,Unauthorized,Forbidden. - Exception Integration: Convert exceptions to
Errorobjects or wrapErrorobjects inDomainException.
📦 Installation
dotnet add package CSharpEssentials.Errors
🛠 Usage
1. Creating Errors
Use the static factory methods on the Error struct to create standard errors.
using CSharpEssentials.Errors;
// Common error types
var notFound = Error.NotFound("User.NotFound", "The user with the specified ID was not found.");
var validation = Error.Validation("User.EmailInvalid", "The email address is in an invalid format.");
var conflict = Error.Conflict("User.AlreadyExists", "A user with this email already exists.");
var failure = Error.Failure("Payment.Failed", "The payment gateway rejected the transaction.");
2. Error Metadata
You can attach extra information to an error for debugging or client responses.
var metadata = new ErrorMetadata
{
{ "RetryCount", 3 },
{ "Gateway", "Stripe" }
};
var error = Error.Failure(
code: "Payment.Failed",
description: "Transaction failed",
metadata: metadata
);
3. Converting Exceptions to Errors
Capture exception details into a structured error.
try
{
// ... risky code ...
}
catch (Exception ex)
{
var error = Error.Exception(
code: "System.Unhandled",
exception: ex
);
// error.Description will be ex.Message
// error.Metadata will contain exception details
}
4. Domain Exceptions
If you must throw an exception but want to keep the structured error format (e.g., to be caught by a global handler), use DomainException.
using CSharpEssentials.Exceptions;
public void DoSomething()
{
var error = Error.Validation("Input.Invalid", "Value cannot be negative");
throw new DomainException(error);
}
5. Error Equality
Errors are value types and check for equality based on their content (Code, Description, Type, Metadata).
var e1 = Error.NotFound("Item.Missing");
var e2 = Error.NotFound("Item.Missing");
bool areEqual = (e1 == e2); // True
| 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.2)
- CSharpEssentials.Enums (>= 3.0.2)
- System.Text.Json (>= 9.0.0)
-
net10.0
- CSharpEssentials.Core (>= 3.0.2)
- CSharpEssentials.Enums (>= 3.0.2)
-
net11.0
- CSharpEssentials.Core (>= 3.0.2)
- CSharpEssentials.Enums (>= 3.0.2)
-
net9.0
- CSharpEssentials.Core (>= 3.0.2)
- CSharpEssentials.Enums (>= 3.0.2)
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 | 25 | 5/7/2026 |
| 3.0.4 | 133 | 5/6/2026 |
| 3.0.3 | 180 | 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 |