CallgraphClosure.MustNotAllocate 0.1.0-preview2

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

CallgraphClosure.MustNotAllocate

A Roslyn analyzer (plus optional Cecil IL post-pass) that enforces a [MustNotAllocate] contract on annotated methods. Flags allocations and unannotated calls reachable through the transitive call closure.

Pre-release. This is an early-stage package. APIs and diagnostics may change. Virtual/interface dispatch is not yet covered — see the repo's docs/ROADMAP.md.

Install

dotnet add package CallgraphClosure.MustNotAllocate --prerelease

Use

using CallgraphClosure.Attributes;

internal sealed class HotLoop
{
    [MustNotAllocate]
    public void Tick(int n)
    {
        Console.WriteLine(n);          // CGC002: external call, deferred to IL pass
        var buf = new int[16];         // CGC003: array allocation in annotated method
    }
}

Diagnostics:

ID Meaning
CGC001 Annotated method calls an unannotated method — annotate the callee or stop calling it
CGC002 Annotated method calls an external (BCL/3rd-party) method whose status the analyzer can't verify; resolved by the IL post-pass
CGC003 Annotated method directly performs a forbidden operation (here: an allocation)

How it works

The Roslyn analyzer walks the call graph from each [MustNotAllocate] method through whatever source it can see and reports any direct violations plus any forbidden operation found along an annotated transitive path. Calls into external assemblies (where source isn't available at edit time) are flagged as deferred — the optional IL post-pass (CallgraphClosure.ILCheck) resolves those at build time by walking the IL of the loaded assembly graph.

Repo

github.com/pawlos/covenant — full design notes, IL post-pass details, and the other property analyzers in the family (MustNotThrow, MustNotBlock, MustNotRecurse).

MIT licensed.

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on CallgraphClosure.MustNotAllocate:

Package Downloads
CallgraphClosure

Meta-package for the CallgraphClosure family of property analyzers. Installing this pulls in all four current properties (MustNotAllocate, MustNotThrow, MustNotBlock, MustNotRecurse). Pre-release.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.0-preview2 63 5/25/2026
0.1.0-preview1 64 5/18/2026