dotnet-aot-compat

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

Updated Jul 12, 2026
One-click install
npx skills add https://github.com/Patrick-Rex/DotNetTechSamples --skill dotnet-aot-compat-patrick-rex
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dotnet-aot-compat
Source: https://github.com/Patrick-Rex/DotNetTechSamples/tree/main/.agents/plugins/dotnet-upgrade/skills/dotnet-aot-compat
Command: npx skills add https://github.com/Patrick-Rex/DotNetTechSamples --skill dotnet-aot-compat-patrick-rex

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Enabling Native AOT or trimming on a .NET project surfaces dozens of IL analyzer warnings (IL2026, IL2070, IL3050, etc.) caused by reflection-based code that 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 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 configuration. - Use Case: After upgrading a library to net8.0, you get 40 IL2026 warnings from JsonSerializer calls. The Skill guides you to create one JsonSerializerContext and batch-update all call sites, then cascade annotations outward for the remaining warnings. ## Quick Start Ask the AI to make your .NET project AOT-compatible by fixing all IL trim warnings in the specified .csproj file.

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 trimming warnings in .NET?

IL2070 means a reflection call operates 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?

Create a JsonSerializerContext with [JsonSerializable] attributes for every type you own, then replace JsonSerializer.Serialize(obj) and Deserialize<T>(json) calls with overloads taking MyContext.Default.TypeName. This eliminates IL2026 and IL3050 warnings in bulk.

Can I suppress IL trim warnings with pragma warning disable?

No. #pragma warning disable only hides warnings from the Roslyn analyzer at build time; the IL linker and AOT compiler still see the issue and the code fails at publish time. Fix the underlying annotation flow instead.

Does Native AOT analysis work on netstandard2.0 or .NET Framework projects?

The trim and AOT analyzers require net8.0 or later. For multi-targeting projects, condition IsAotCompatible on the TFM and add polyfill attributes for DynamicallyAccessedMembersAttribute on netstandard2.0 or net472 targets.

What should I do when a method fundamentally requires reflection?

Mark it with [RequiresUnreferencedCode] or [RequiresDynamicCode] so the requirement propagates to callers explicitly. Use this only as a last resort after annotation and refactoring strategies fail, since it marks the call chain as trim-incompatible.