CrCore.Exceptions.AspNetCore 10.0.47

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

Intro

ASP.NET Core integration for Cr.Exceptions to automatically map exceptions into RFC-compliant Problem Details with customizable HTTP status codes and log levels.


Installation

Default

builder.Services.AddCrExceptionHandling();
app.UseExceptionHandler();

Custom

builder.Services
    .AddCrExceptionHandler()
    .AddCrStatusCodeMapping(builder =>
    {
        // Configure
    })
    .AddCrLogLevelMapping(builder =>
    {
        // Configure
    });

app.UseExceptionHandler();

Exception Handling

Flow

When a CrException is thrown:

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

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

The client receives a next response:

{
    "type": "https://tools.ietf.org/html/rfc9110#section-15.5.1",
    "title": "Bad Request",
    "status": 400,
    "errors": [
        {
            "code": "IdentityInvalidGrant",
            "message": "The authorization grant is invalid."
        }
    ],
    "traceId": "6dd0bbb69ae26c77dd09d915915b1958"
}

traceId populates from Activity.Current?.TraceId with a fallback to HttpContext.TraceIdentifier.

If an exception is not derived from CrException, or for any unknown exception, the handler returns the following fallback response:

{
  "type": "https://tools.ietf.org/html/rfc9110#section-15.6.1",
  "title": "An error occurred while processing your request.",
  "status": 500,
  "errors": [
    {
      "code": "InternalError",
      "message": "An unexpected internal error occurred."
    }
  ],
  "traceId": "ff3e0d35e6f0fa022a6de34583ea9e81"
}

Logging

The handler emits structured logs for exceptions and handling events. See Log Event IDs.


HTTP Status Code Mapping

You can customize how CrException types map to HTTP status codes.

The mapping process traverses the exception type hierarchy.

Registration

builder.Services.AddCrStatusCodeMapping(builder =>
{
    builder.AddDefaultMappings();

    builder.Map<MyCustomException>(StatusCodes.Status499ClientClosedRequest);
});

See Default Mappings.


Log Level Mapping

You can customize how CrException types map to a LogLevel.

The mapping process traverses the exception type hierarchy.

Registration

builder.Services.AddCrLogLevelMapping(builder =>
{
    builder.AddDefaultMappings();

    builder.Map<MyCustomException>(LogLevel.Warning);
});

See Default Mappings.

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

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 99 11/29/2026
10.0.47 112 10/29/2026
10.0.46 183 9/20/2026