dotnet-aot-compat

Resolve IL trim and AOT analyzer warnings to make .NET projects Native AOT compatible.

1|Updated Jun 1, 2026
One-click install
npx skills add https://github.com/D1ssolve/craft-agents --skill dotnet-aot-compat-d1ssolve
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dotnet-aot-compat
Source: https://github.com/D1ssolve/craft-agents/tree/main/skills/dotnet-aot-compat
Command: npx skills add https://github.com/D1ssolve/craft-agents --skill dotnet-aot-compat-d1ssolve

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Enabling Native AOT or trimming in .NET projects surfaces dozens of IL analyzer warnings (IL2026, IL2070, IL3050, etc.) caused by reflection patterns the trimmer cannot statically verify. This Skill provides a systematic, warning-driven workflow to fix every warning without suppressing them incorrectly. ## Core Features & Use Cases - Warning-driven fix loop: Enable IsAotCompatible, build, triage warnings by code, and apply targeted fix recipes iteratively until zero IL warnings remain. - Four fix strategies: Add DynamicallyAccessedMembers annotations, refactor to preserve annotation flow, batch-migrate JsonSerializer calls to source-generated JsonSerializerContext, or apply RequiresUnreferencedCode as a last resort. - Multi-targeting support: Includes polyfills for DynamicallyAccessedMembersAttribute on netstandard2.0 and net472, plus TFM-conditional IsAotCompatible configuration. - Use Case: After upgrading a library to net8.0, the build emits 40 IL2026 warnings from JsonSerializer calls. The Skill guides creating one JsonSerializerContext and batch-updating all call sites, then resolving remaining annotation warnings. ## Quick Start Make my .NET project AOT-compatible by fixing all IL trim and AOT analyzer warnings.

Frequently Asked Questions about dotnet-aot-compat

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix IL2070 trim warnings in .NET?

IL2070 occurs when reflection is called on a Type parameter lacking annotations. Add [DynamicallyAccessedMembers] with the required member types (e.g., PublicMethods) to the parameter, then cascade matching annotations outward to all callers.

How do I make JsonSerializer AOT-compatible in .NET?

Create a JsonSerializerContext with [JsonSerializable] attributes for each type you own, then replace JsonSerializer.Serialize(obj) and Deserialize<T>(json) calls with overloads taking MyContext.Default.TypeName. This removes reflection-based serialization warnings IL2026 and IL3050.

Why should I not use #pragma warning disable for IL warnings?

The pragma hides warnings from the Roslyn analyzer at build time, but the IL linker and AOT compiler still encounter the issue, causing failures at trim or publish time. Fix the underlying annotation flow or use [RequiresUnreferencedCode] instead.

Does Native AOT trimming work with netstandard2.0 or net472 targets?

The trim and AOT analyzers require net8.0 or later, so apply IsAotCompatible with a TFM condition for multi-targeting projects. For older TFMs, add a polyfill defining DynamicallyAccessedMembersAttribute locally since the trimmer recognizes it by name.

When should I use RequiresUnreferencedCode instead of annotations?

Use [RequiresUnreferencedCode] only as a last resort when a method fundamentally requires arbitrary reflection that cannot be statically described, such as Assembly.Load by name. It propagates the requirement to all callers, marking the whole call chain trim-incompatible.

How do I handle external types that are not AOT-safe for serialization?

Do not add external types to your JsonSerializerContext since source generation only works for types you own. If the type implements IJsonModel<T> (common in Azure SDK), call its Write/Create methods directly; otherwise write a custom JsonConverter<T>.