On4Net.Extensions.Exception 10.0.2

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

On4Net.Extensions.Exception

Domain-specific exceptions and an extension to map any System.Exception to a consistent API payload (ErrorResponse). Namespace: On4Net.Extensions.Exception.


AppException — AppException.cs

Abstract base for application errors.

Member What it does
MessageId (string) Stable id for clients / localization keys.
StatusCode (int) Suggested HTTP status.
Params (object[]?) Optional template parameters.
.ctor(messageId, message, statusCode = 500, params = null) Protected constructor; sets base Exception.Message.

Derived exceptions

Type File Constructors / behavior
NotFoundException NotFoundException.cs NotFound message id, default HTTP 404; exposes EntityName; overloads with id or custom message.
DuplicateKeyException DuplicateKeyException.cs DuplicateKey message id, default 409; exposes EntityName.
ConcurrencyException ConcurrencyException.cs Concurrency message id, default 409.
DataValidationException DataValidationException.cs Validation message id, default 400.
ArgumentException ArgumentException.cs Note: this is On4Net.Extensions.Exception.ArgumentException, not System.ArgumentException. Message id Argument, default 403.
ApplicationException ApplicationException.cs Concrete AppException for unforeseen or unexpected application/domain errors you still want to return through the same contract (MessageId, HTTP StatusCode, optional Params) instead of a bare System.Exception. Same constructor as AppException (messageId, message, statusCode, params). Note: type name is On4Net.Extensions.Exception.ApplicationException, not System.ApplicationException.

ErrorResponse — ErrorResponse.cs

DTO for API error bodies.

Property What it does
StatusCode HTTP status.
MessageId Error identifier.
Message Human-readable text.
Params Extra key/value data (entity names, validation fields, etc.).

ExceptionHandler — ExceptionHandler.cs

Method Location What it does
GetErrorFromException(this System.Exception exception) ExceptionHandler.cs Maps exception to ErrorResponse: AppException — copies MessageId, Message, StatusCode, wraps Params; NotFoundException — adds EntityName; ValidationException (DataAnnotations) — flattens Data to dictionary; DuplicateKeyException — EntityName; On4Net.Extensions.Exception.ArgumentException — from Data; NotImplementedException / NotSupportedException — MessageId NotImplementedOrNotSupported, status 500; ArgumentNullException / ArgumentOutOfRangeException / System.ArgumentException — status 400; default — generic Exception, status 500.

Use from global exception middleware or a central filter to return uniform JSON errors.


Project layout

On4Net.Extensions.Exception/
├── AppException.cs
├── ApplicationException.cs
├── ArgumentException.cs
├── ConcurrencyException.cs
├── DataValidationException.cs
├── DuplicateKeyException.cs
├── ErrorResponse.cs
├── ExceptionHandler.cs
├── NotFoundException.cs
└── (namespace On4Net.Extensions.Exception)
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.0.2 126 4/26/2026
10.0.1 122 4/25/2026
10.0.0 111 4/25/2026