ZeroAlloc.Analyzers
1.11.3
dotnet add package ZeroAlloc.Analyzers --version 1.11.3
NuGet\Install-Package ZeroAlloc.Analyzers -Version 1.11.3
<PackageReference Include="ZeroAlloc.Analyzers" Version="1.11.3"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="ZeroAlloc.Analyzers" Version="1.11.3" />
<PackageReference Include="ZeroAlloc.Analyzers"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add ZeroAlloc.Analyzers --version 1.11.3
#r "nuget: ZeroAlloc.Analyzers, 1.11.3"
#:package ZeroAlloc.Analyzers@1.11.3
#addin nuget:?package=ZeroAlloc.Analyzers&version=1.11.3
#tool nuget:?package=ZeroAlloc.Analyzers&version=1.11.3
ZeroAlloc.Analyzers
Roslyn analyzers that catch allocations and NativeAOT breakers at compile time: 64 rules for the performance patterns the built-in .NET analyzers miss, each silenced automatically where your target framework can't use the fix.
Why ZeroAlloc.Analyzers
- Find allocations in the build, not in a profiler. Boxing in string concatenation, LINQ in loops, double dictionary lookups, closures, uncached delegates and missed
FrozenDictionaryopportunities show up as warnings where you write the code. - Catch NativeAOT breakers early. The ZA17xx rules flag
Expression.Compile,Reflection.Emit, reflection-based serializers,dynamicand assembly-scanning registration before a trimmed or AOT publish fails. - Every diagnostic is actionable. Rules that need .NET 5, 6, 7, 8 or 9, or a newer C# version, are silenced on older targets, so you never see a fix for an API you can't call.
- A few percent of build time. On a 240-file sample, a median of +2.1% for a full
net8.0build and +2.9% for a one-file edit; a build with no changes runs no analyzers at all.
Install
dotnet add package ZeroAlloc.Analyzers
It is a development dependency: nothing flows to your consumers, and there is no runtime assembly.
Quick start
Build, and the diagnostics appear in dotnet build, Visual Studio, Rider and VS Code with C# Dev Kit:
public sealed class PriceCache
{
private readonly Dictionary<string, decimal> _prices = new();
public decimal Get(string sku)
{
// warning ZA0105: Use 'TryGetValue' instead of 'ContainsKey' followed by indexer access
if (_prices.ContainsKey(sku))
return _prices[sku];
return 0m;
}
}
Apply the code fix from the lightbulb, or with dotnet format, and the two lookups become one:
if (_prices.TryGetValue(sku, out var value))
return value;
What you get
- 64 rules in 15 categories, each with its own page: collections, strings, memory, logging, boxing, LINQ, regex, enums, sealing, serialization, async, delegates, value types, data layout and Native AOT.
- Code fixes for eight rules, applied from the IDE or with
dotnet format. - Multi-target aware: each target framework of a multi-targeted project gets exactly the rules that apply to it.
- Standard severity control through
.editorconfig, includingTreatWarningsAsErrors. Configuration - Guidance for test projects, where some rules are noise. Testing
Performance
Build overhead on a 240-file, 18,000-line sample, relative to the same project built without the package; median of 15 interleaved pairs.
| Target | Full build | One-file edit |
|---|---|---|
net8.0 |
+2.1% | +2.9% |
net8.0 + netstandard2.0 |
+4.3% | +5.4% |
netstandard2.0 |
+10.5% | +23.0% |
A build with no changes does not run the compiler, so the analyzers add no work. The overhead is largest on netstandard2.0, where the SDK's own analyzers don't run and the build is smaller.
How many rules run per target, the spread, the environment, the harness to reproduce it and tips for fast local builds: docs/performance.md.
Learn more
- Documentation: analyzers.zeroalloc.net
- Related packages: ZeroAlloc.TestHelpers proves zero-allocation claims in tests, and the ZeroAlloc family of libraries, which build with these rules
- Contributing: issues and pull requests are welcome on GitHub; see the contributor docs
- License: MIT
Learn more about Target Frameworks and .NET Standard.
This package has 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 |
|---|---|---|
| 1.11.3 | 42 | 10/23/2026 |
| 1.11.2 | 12,881 | 10/16/2026 |
| 1.11.1 | 3,064 | 10/15/2026 |
| 1.11.0 | 17,380 | 10/10/2026 |
| 1.10.0 | 192 | 10/10/2026 |
| 1.9.0 | 1,397 | 10/9/2026 |
| 1.8.0 | 189 | 10/9/2026 |
| 1.7.0 | 242 | 10/9/2026 |
| 1.6.0 | 135 | 10/9/2026 |
| 1.5.6 | 971 | 10/9/2026 |
| 1.5.5 | 239 | 10/9/2026 |
| 1.5.4 | 20,952 | 9/25/2026 |
| 1.5.3 | 5,351 | 9/20/2026 |
| 1.5.2 | 1,071 | 9/19/2026 |
| 1.5.1 | 152 | 9/19/2026 |
| 1.5.0 | 11,776 | 6/27/2026 |
| 1.4.0 | 212 | 6/27/2026 |
| 1.3.15 | 4,426 | 4/29/2026 |
| 1.3.14 | 432 | 4/28/2026 |
| 1.3.13 | 390 | 4/20/2026 |