Lyo.Exceptions 1.0.0

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

Lyo.Exceptions

Custom exception types and argument validation helpers for the Lyo library suite. Used across all Lyo packages for consistent error handling and validation.

Features

  • ArgumentHelpers – Argument validation with ThrowIfNull, ThrowIfNullOrWhiteSpace, ThrowIfNullOrEmpty, ThrowIf, ThrowIfNotInRange, ThrowIfFileNotFound, ThrowIfNullReturn (for constructor chaining), plus ThrowIfEmpty (GUIDs), ThrowIfDefault (structs such as DateTime), ThrowIfNotDefined (enum casts), and ThrowIfIndexOutOfRange
  • UriHelpers – URI validation with GetValidWebUri, ThrowIfInvalidUri, ThrowIfInvalidAbsoluteUri
  • OperationHelpers – Operation/state validation (ThrowIf, ThrowIfNull, ThrowIfNullOrWhiteSpace, stream checks, disposition/cancellation/not-supported) plus numeric parity with ArgumentHelpers: ThrowIfNotInRange (scalar, DateTime, TimeSpan, array lengths), ThrowIfGreaterThan, ThrowIfGreaterThanOrEqual, ThrowIfLessThan, ThrowIfLessThanOrEqual, ThrowIfZero, sign helpers, ThrowIfEqual, ThrowIfNotEqual
  • OrThrow / StringOr – Fluent string?.Or / .OrIfWhiteSpace chains and terminals (OrThrowInvalidOperation, OrThrow(Func<…>), etc.) plus generic OrThrowInvalidOperation/OrThrow unwraps—implemented here so callers do not pull in Lyo.Common for throw-only ergonomics
  • FileHelpers – File name validation with ThrowIfFileNameInvalid, GetValidFileName, and path-prefix safety helpers NormalizePathPrefix, ThrowIfPathPrefixTraversal, NormalizeAndValidatePathPrefix (shared by every Lyo.FileStorage backend's save/direct-upload/diagnostics paths)
  • FormatHelpers – Format validation throwing InvalidFormatException (ThrowIfInvalidGuid, GetValidGuid, hex color, ThrowIfInvalidFormat with custom regex, ThrowIfInvalidPort / IsValidPort for 1–65535, ThrowIfNotInRange for numeric options checks, etc.)
  • ConfigurationHelpers – Configuration validation throwing ConfigurationException (ThrowIf, ThrowIfNull, ThrowIfNullOrWhiteSpace) with caller-expression setting names
  • ExceptionThrower – File/directory existence and accessibility (ThrowIfDirectoryNotFound, ThrowIfFileNotAccessible, ThrowIfDirectoryNotAccessible)
  • Custom exceptionsArgumentOutsideRangeException, InvalidFormatException, ConfigurationException, HttpException (base for BadRequestException, UnauthorizedException, ForbiddenException, NotFoundException, ConflictException, GoneException, UnprocessableEntityException, RateLimitExceededException, ServiceUnavailableException, GatewayTimeoutException), and more
  • HttpException extras – every HttpException carries an optional machine-readable ErrorCode (init-only) and an IsTransient flag (true for 429/503/504) that retry policies can use as a single predicate; HttpExceptions.FromStatusCode(statusCode, message) maps raw status codes to the dedicated types (or GenericHttpException for unknown codes), and NotFoundException/ConflictException/ForbiddenException/GoneException expose ForResource(name, id) factories that always set the resource properties (avoiding the new NotFoundException("User", null) constructor-overload trap)
  • ValidationErrorsBuilder – accumulates field-level errors (Add, AddIf, AddRange) and throws a single ValidationException via ThrowIfAny() only when errors exist

Examples

Quick Start

using Lyo.Exceptions;

// Argument validation
public void Process(string name, byte[] data)
{
    ArgumentHelpers.ThrowIfNullOrWhiteSpace(name);
    ArgumentHelpers.ThrowIfNullOrEmpty(data);
    // ...
}

// Constructor chaining
public MyService(IOptions options, ILogger logger)
    : base(ArgumentHelpers.ThrowIfNullReturn(options), logger)
{
}

// URI validation
var uri = UriHelpers.GetValidWebUri(url);

// Operation state (builder/build validation)
OperationHelpers.ThrowIfNull(_data, "Data must be specified using WithData()");
OperationHelpers.ThrowIf(_count == 0, "At least one item is required");

// New guards
ArgumentHelpers.ThrowIfEmpty(tenantId); // Guid.Empty
ArgumentHelpers.ThrowIfDefault(createdAt); // default(DateTime)
ArgumentHelpers.ThrowIfNotDefined((DayOfWeek)value); // undefined enum cast
ArgumentHelpers.ThrowIfIndexOutOfRange(index, items.Count);

// HTTP exceptions with error codes and resource factories
throw NotFoundException.ForResource("User", userId);
throw new ConflictException("Order already submitted.") { ErrorCode = "order.already_submitted" };
var ex = HttpExceptions.FromStatusCode(503, "Upstream unavailable."); // ex.IsTransient == true

// Accumulate validation errors, throw once
var errors = new ValidationErrorsBuilder()
    .AddIf(string.IsNullOrWhiteSpace(req.Email), nameof(req.Email), "Email is required.")
    .AddIf(req.Age < 0, nameof(req.Age), "Age must be positive.");
errors.ThrowIfAny();
Product 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 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.
  • net10.0

    • No dependencies.

NuGet packages (117)

Showing the top 5 NuGet packages that depend on Lyo.Exceptions:

Package Downloads
Lyo.Common

Common utilities, extensions, enums, JSON converters, and helper classes for the Lyo library suite.

Lyo.Result

Result, Error, Option, and validation primitives for the Lyo library suite.

Lyo.Metrics

Metrics collection and reporting library with support for counters, timers, and snapshots. Provides a pluggable metrics interface for integration with various metrics backends.

Lyo.Hashing

Digests, hex encoding, hashing streams, non-cryptographic checksums (CRC/Adler), lightweight file fingerprints (non-security), and optional hashing service.

Lyo.Query.Models

Query models for building and representing queries - QueryNode, QueryRequest, ConditionNode, SortBy, builders. Shared by Lyo.Query and Lyo.Api.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 357 8/16/2026