dotnet-aot-compat

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

Updated Sep 22, 2026
One-click install
npx skills add https://github.com/bytecakelake/Nurse-Scheduler --skill dotnet-aot-compat-bytecakelake
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: dotnet-aot-compat
Source: https://github.com/bytecakelake/Nurse-Scheduler/tree/main/.agents/plugins/dotnet-upgrade/skills/dotnet-aot-compat
Command: npx skills add https://github.com/bytecakelake/Nurse-Scheduler --skill dotnet-aot-compat-bytecakelake

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Enabling Native AOT or trimming on a .NET project floods the build with IL analyzer warnings (IL2026, IL2070, IL3050, and more) caused by reflection patterns the trimmer cannot statically verify. This Skill provides a systematic, warning-driven workflow to fix every warning correctly without unsafe suppressions. ## 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 broken annotation flow, batch-migrate JsonSerializer calls to source-generated JsonSerializerContext, or mark fundamentally incompatible methods with [RequiresUnreferencedCode]. - Multi-targeting support: Includes polyfills for DynamicallyAccessedMembersAttribute on netstandard2.0 and net472, plus TFM-conditional IsAotCompatible setup. - Use Case: After upgrading a library to net8.0, you enable AOT analysis and get 200 IL2026 warnings from JsonSerializer. The Skill guides you to create one JsonSerializerContext and batch-update all call sites, then cascade annotations for the remaining reflection warnings. ## Quick Start Ask the AI to make your .NET project AOT-compatible by fixing all IL trim 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 make a .NET project Native AOT compatible?▼

Enable IsAotCompatible in the .csproj conditioned on net8.0 or later, then build and fix each IL analyzer warning iteratively. Add DynamicallyAccessedMembers annotations to reflection-based APIs and migrate JsonSerializer calls to a source-generated JsonSerializerContext.

How to fix IL2026 and IL3050 warnings from JsonSerializer?▼

Create a JsonSerializerContext with a JsonSerializable attribute for every type you own, then batch-update call sites to pass MyContext.Default.TypeName to Serialize and Deserialize. This replaces reflection-based serialization with source generation.

Can I suppress IL trim warnings with pragma warning disable?▼

No. Pragma suppressions hide warnings from the Roslyn analyzer but the IL linker and AOT compiler still see the issue, so the code fails at trim or publish time. Use DynamicallyAccessedMembers annotations or RequiresUnreferencedCode instead.

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

The trim and AOT analyzers require net8.0 or later, so condition IsAotCompatible on the target framework. For older TFMs in multi-targeted projects, add a polyfill of DynamicallyAccessedMembersAttribute since the trimmer recognizes it by name.

Why does the trimmer warn when a Type is passed through object arrays?▼

Boxing a Type into object or object[] breaks the DynamicallyAccessedMembers annotation flow, so the trimmer loses track of required members and warns with IL2072. Refactor to pass the Type as a dedicated annotated parameter.

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 trim-incompatibility to all callers, so prefer annotation fixes first.