CrCore.Exceptions.AspNet 10.0.33

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

Intro

A lightweight library for defining application exceptions and automatically converting them into HTTP responses in ASP.NET Core.

Installation

Register the exception handler during application startup.

builder.Services.AddCrExceptionHandler();

Or configure custom exception mappings.

builder.Services.AddCrExceptionHandler(options =>
{
    options.ExceptionMapping.AddDefaultMappings();
    options.ExceptionMapping.Map<MyCustomException>(499);
});

Enable exception handling middleware.

app.UseExceptionHandler();

Creating a Custom Exception

Create your own exception by inheriting from one of the provided exception categories.

Example:

public sealed class UserNotFoundException : NotFoundException
{
    public UserNotFoundException(Guid userId) : base(
	[new CrError("UserNotFound", $"User '{userId}' was not found.")],
        "User was not found.")
    {
    }
}
public sealed record class CrError(string Code, string Message);

Each error provides:

  • Code — unique identifier used by clients.
  • Message — human-readable error description.

Throwing an Exception

Throw your custom exception normally.

throw new UserNotFoundException(userId);

The exception handler automatically converts it into an RFC 7807 ProblemDetails response.

Example:

{
  "type": "about:blank",
  "title": "Not Found",
  "status": 404,
  "detail": "User was not found.",
  "instance": "/api/users/123",
  "traceId": "0HNNAF6ABMHQO",
  "errors": [
    {
      "code": "UserNotFound",
      "message": "User '123' was not found."
    }
  ]
}

Default Exception Mappings

Exception Category HTTP Status
ValidationException 400 Bad Request
UnauthorizedException 401 Unauthorized
ForbiddenException 403 Forbidden
NotFoundException 404 Not Found
ConflictException 409 Conflict
UnprocessableException 422 Unprocessable Entity

Internal Errors

Unexpected exceptions are automatically converted into a generic internal error response.

Example:

{
  "type": "about:blank",
  "title": "Internal Server Error",
  "status": 500,
  "detail": "An unexpected error occurred.",
  "instance": "",
  "traceId": "0HNNAF6ABMHQO",
  "errors": [
    {
      "code": "InternalError",
      "message": "An unexpected internal error occurred."
    }
  ]
}
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.0.45 91 8/7/2026
10.0.44 98 8/5/2026
10.0.43 94 8/3/2026
10.0.42 98 8/1/2026
10.0.41 100 8/1/2026
10.0.40 99 7/30/2026
10.0.33 96 7/27/2026