Native AOT and trimming
Nullean.Argh is AOT-safe and trimming-safe by default. The source generator emits all parsing, routing, dispatch, and help code directly into your assembly at build time. No reflection, no dynamic dispatch.
- No reflection - all type binding, parameter parsing, and dispatch is generated as static C# code
- No dynamic dispatch - the generated switch tree routes directly to handler methods
- Trimming-safe - no hidden dependencies that the trimmer might remove
- AOT-compatible - works with
PublishAot=truewithout any special configuration
When using Nullean.Argh.Hosting with native AOT, register handler and middleware types explicitly in DI so required constructors are preserved:
builder.Services.AddScoped<DeployCommands>();
builder.Services.AddSingleton<AuditMiddleware>();
builder.Services.AddArgh(args, b =>
{
b.MapScoped<DeployCommands>();
b.UseMiddleware<AuditMiddleware>(ServiceLifetime.Singleton);
});
Lambda handlers (UseMiddleware inline delegates) are the one exception to the zero-reflection rule and emit warning AGH0006. Prefer method groups or class registration for AOT-published apps.
The project includes an aot-validate CI job that publishes with Native AOT on Linux, macOS, and Windows and invokes __schema on the native binary to verify correct operation.
Generated code targets netstandard2.0 (no System.Linq, no pattern features beyond what that TFM allows). The static extension methods in ArghTypeBindingExtensions.g.cs require C# 14 preview (static extension members).