ZeroAlloc.Validation
2.1.0
dotnet add package ZeroAlloc.Validation --version 2.1.0
NuGet\Install-Package ZeroAlloc.Validation -Version 2.1.0
<PackageReference Include="ZeroAlloc.Validation" Version="2.1.0" />
<PackageVersion Include="ZeroAlloc.Validation" Version="2.1.0" />
<PackageReference Include="ZeroAlloc.Validation" />
paket add ZeroAlloc.Validation --version 2.1.0
#r "nuget: ZeroAlloc.Validation, 2.1.0"
#:package ZeroAlloc.Validation@2.1.0
#addin nuget:?package=ZeroAlloc.Validation&version=2.1.0
#tool nuget:?package=ZeroAlloc.Validation&version=2.1.0
ZeroAlloc.Validation
Source-generated, attribute-based validation for .NET that allocates nothing on the valid path. The source generator emits a strongly-typed validator class at build time — no reflection at runtime. When all rules pass, the entire validation cycle produces zero heap allocations.
Install
dotnet add package ZeroAlloc.Validation
ZeroAlloc.Validation bundles its own source generator — no other package is required.
Upgrading from an older version? If your project also references
ZeroAlloc.Validation.Generatordirectly, remove thatPackageReference— the generator now ships insideZeroAlloc.Validationitself, and keeping both loads it twice, which fails the build withZV9001.
30-Second Example
using ZeroAlloc.Validation;
[Validate]
public class CreateOrderRequest
{
[NotEmpty][MaxLength(50)] public string Reference { get; set; } = "";
[GreaterThan(0)] public decimal Amount { get; set; }
[NotEmpty][EmailAddress] public string Email { get; set; } = "";
}
// The source generator emits CreateOrderRequestValidator at build time
var request = new CreateOrderRequest
{
Reference = "ORD-2026-001",
Amount = 99.99m,
Email = "customer@example.com"
};
var validator = new CreateOrderRequestValidator();
var result = validator.Validate(request);
if (!result.IsValid)
foreach (ref readonly var f in result.Failures)
Console.WriteLine($"{f.PropertyName}: {f.ErrorMessage}");
Performance
| Scenario | ZeroAlloc.Validation | FluentValidation | Speedup | Allocation (valid) |
|---|---|---|---|---|
| Flat model | 6.7 ns | 327 ns | ~49× | 0 B |
| Nested model | 10.1 ns | 619 ns | ~61× | 0 B |
| Collection (3×) | 14.3 ns | 2,043 ns | ~143× | 0 B |
See Performance for full benchmark results.
Packages
| Package | Purpose |
|---|---|
ZeroAlloc.Validation |
Core library — attributes, source generator, ValidationResult |
ZeroAlloc.Validation.AspNetCore |
Auto-validates request models; returns HTTP 422 on failure |
ZeroAlloc.Validation.Inject |
Emits AddZeroAllocValidators() — bulk DI registration in one call |
ZeroAlloc.Validation.Options |
Emits ValidateWithZeroAlloc() — plugs validators into Microsoft.Extensions.Options |
ZeroAlloc.Validation.Testing |
Fluent assertions for unit-testing validators |
ZeroAlloc.Validation.Generator |
Deprecated. Bundled into ZeroAlloc.Validation itself; do not reference directly |
Features
- Zero heap allocation on the valid path
- 25+ built-in validation attributes
- Nested object and collection validation
- Inherited rules from base types (opt out with
[Validate(IncludeBaseProperties = false)]) - ASP.NET Core auto-validation (HTTP 422 on failure)
- Zero-friction DI registration (
AddZeroAllocValidators()) - Source-generated
Microsoft.Extensions.Optionsintegration (ValidateWithZeroAlloc()) - Per-rule severity (
Error,Warning,Info) - Conditional rules (
When/Unless/[SkipWhen]) - Short-circuit with
[StopOnFirstFailure] - Custom rules via reusable
ValidationAttribute<T>attributes,[Must]predicates or[CustomValidation]methods - Asynchronous rules via
AsyncValidationAttribute<T>, awaited by the generatedValidateAsync - Testing helpers via
ZeroAlloc.Validation.Testing
Documentation
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. 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 is compatible. 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. |
-
net10.0
- ZeroAlloc.Pipeline (>= 1.4.0)
-
net8.0
- ZeroAlloc.Pipeline (>= 1.4.0)
-
net9.0
- ZeroAlloc.Pipeline (>= 1.4.0)
NuGet packages (13)
Showing the top 5 NuGet packages that depend on ZeroAlloc.Validation:
| Package | Downloads |
|---|---|
|
ZeroAlloc.Mediator.Validation
Pipeline behavior that validates IRequest<T> via ZeroAlloc.Validation before dispatch. Validation failures surface as Result<T, ValidationError> — no exceptions on the hot path. |
|
|
AI.Sentinel
Security monitoring middleware for IChatClient — prompt injection, hallucination, and operational anomaly detection with an intervention engine. |
|
|
ZeroAlloc.Validation.AspNetCore
ASP.NET Core integration for ZeroAlloc.Validation. Source-generated action filter validates request models at compile time with zero runtime overhead. |
|
|
ZeroAlloc.Validation.Testing
Testing helpers for ZeroAlloc.Validation. Provides assertion utilities to verify validation results in unit tests. |
|
|
Thalos.NET.Abstractions
Ports and models for Thalos.NET. Depends only on ZeroAlloc primitives and Microsoft.Extensions.AI.Abstractions. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.1.0 | 58 | 9/30/2026 |
| 2.0.3 | 262 | 9/30/2026 |
| 2.0.2 | 487 | 9/28/2026 |
| 2.0.1 | 454 | 9/27/2026 |
| 2.0.0 | 323 | 9/26/2026 |
| 1.7.8 | 1,654 | 9/24/2026 |
| 1.7.7 | 128 | 9/24/2026 |
| 1.7.6 | 120 | 9/24/2026 |
| 1.7.5 | 1,970 | 9/21/2026 |
| 1.7.4 | 624 | 9/20/2026 |
| 1.7.3 | 241 | 9/20/2026 |
| 1.7.2 | 160 | 9/20/2026 |
| 1.7.1 | 624 | 9/19/2026 |
| 1.7.0 | 1,803 | 9/12/2026 |
| 1.6.0 | 486 | 9/11/2026 |
| 1.5.9 | 181 | 9/11/2026 |
| 1.5.8 | 237 | 9/11/2026 |
| 1.5.7 | 192 | 9/11/2026 |
| 1.5.6 | 3,033 | 8/9/2026 |
| 1.5.5 | 1,269 | 8/7/2026 |