CrCore.Exceptions 10.1.0

Prefix Reserved
dotnet add package CrCore.Exceptions --version 10.1.0
                    
NuGet\Install-Package CrCore.Exceptions -Version 10.1.0
                    
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="CrCore.Exceptions" Version="10.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CrCore.Exceptions" Version="10.1.0" />
                    
Directory.Packages.props
<PackageReference Include="CrCore.Exceptions" />
                    
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 CrCore.Exceptions --version 10.1.0
                    
#r "nuget: CrCore.Exceptions, 10.1.0"
                    
#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 CrCore.Exceptions@10.1.0
                    
#: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=CrCore.Exceptions&version=10.1.0
                    
Install as a Cake Addin
#tool nuget:?package=CrCore.Exceptions&version=10.1.0
                    
Install as a Cake Tool

Intro

A high-performance .NET library to map external error codes into typed exceptions and translate infrastructure failures into domain exceptions.


Exception Factory

Use Case: Materialize string-based error codes from external APIs into strongly-typed exceptions.

{
  "error": "invalid_grant"
}

Creating

public sealed class KeycloakInvalidGrantException : ValidationException
{
    private static readonly ImmutableArray<CrError> _errors =
        [new("IdentityInvalidGrant", "The authorization grant is invalid.")];

    public KeycloakInvalidGrantException() : base(_errors) { }
}

Registration

var builder = new ExceptionFactoryBuilder()
    .Map("invalid_grant", static () => new KeycloakInvalidGrantException());

var factory = builder.Build();

Receiving

if (factory.TryCreate(errorCode, out var exception)) throw exception;

Exception Translator

Use Case: Catch infrastructure failures and translate them into clean domain exceptions.

The mapping process traverses the exception type hierarchy.

Creating

public sealed class UserInvalidCredentialsException : ValidationException
{
    private static readonly ImmutableArray<CrError> _errors = [new("UserInvalidCredentials")];
    
    public UserInvalidCredentialsException(Exception? innerException = null) : base(_errors, DefaultMessage, innerException) { }
}

Registration

var builder = new ExceptionTranslatorBuilder()
    .Map<KeycloakInvalidGrantException>(static ex => new UserInvalidCredentialsException(ex));

var translator = builder.Build();

Receiving

if (translator.TryTranslate(ex, out var translatedException))
{
    throw translatedException;
}

Core

Base: All custom exceptions inherit from the CrException class. It carries an ImmutableArray of structured error details (zero or more CrError instances):

record class CrError(string Code, string? Message = null);

Exception Categories

Inherit from semantic categories depending on the architectural context:

See the Categories folder for all available built-in exceptions.

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.
  • net10.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
10.1.0 98 11/29/2026
10.0.47 119 10/29/2026
10.0.46 203 9/20/2026