dotnet-aot-compat

Fix .NET Native AOT and trimming IL analyzer warnings.

5.1k|377|Updated Feb 3, 2026
One-click install
npx skills add https://github.com/dotnet/skills --skill dotnet-aot-compat
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dotnet-aot-compat
Source: https://github.com/dotnet/skills/tree/main/plugins/dotnet-upgrade/skills/dotnet-aot-compat
Command: npx skills add https://github.com/dotnet/skills --skill dotnet-aot-compat

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps developers make their .NET projects compatible with Native AOT and trimming by systematically resolving build warnings related to Ahead-Of-Time compilation and code trimming.

Core Features & Use Cases

  • Resolve IL Warnings: Fixes specific IL codes (IL2026, IL2070, IL2067, IL2072, IL3050) that indicate potential issues with Native AOT or trimming.
  • Add Annotations: Guides the addition of [DynamicallyAccessedMembers] annotations to preserve type information for the trimmer.
  • Refactor for Flow: Assists in refactoring code to maintain annotation flow when it's broken by boxing or untyped collections.
  • Use Case: You've upgraded a .NET project to .NET 8 and are encountering numerous trim analyzer warnings. This Skill will guide you through enabling AOT compatibility in your project file, building to collect warnings, and systematically fixing them using annotation and refactoring strategies.

Quick Start

Enable AOT analysis in your .csproj by adding <IsAotCompatible>true</IsAotCompatible> within a PropertyGroup.

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 IL2026 and IL2070 trim warnings in .NET Native AOT projects?

To fix IL2026 and IL2070 trim warnings in .NET Native AOT, you need to add `[DynamicallyAccessedMembers]` annotations to preserve type information and refactor code that breaks annotation flow through boxing or untyped collections.

How do I enable Native AOT compatibility analysis in a .NET 8 project?

Enable Native AOT compatibility analysis in your .NET 8 project by adding `<IsAotCompatible>true</IsAotCompatible>` within a PropertyGroup in your .csproj file, then build the project to identify and resolve generated trim warnings.

What causes IL trim warnings when publishing .NET projects with trimming enabled?

IL trim warnings occur when the .NET trimmer cannot statically guarantee that referenced members will be available at runtime, typically caused by reflection, boxing, or untyped collections that break DynamicallyAccessedMembers annotation flow.

Can I make my existing .NET class library AOT-compatible without targeting net8.0?

No, this Skill is designed specifically for .NET projects targeting net8.0 or later, as Native AOT compatibility features and trim analyzer diagnostics require the modern runtime and compiler support introduced in .NET 8.

How do I refactor code to preserve DynamicallyAccessedMembers annotation flow for AOT?

Preserve DynamicallyAccessedMembers annotation flow for AOT by refactoring code to avoid boxing and untyped collections, ensuring the trimmer can statically track type information from method parameters through to reflection-based member access.

What is the best way to systematically resolve IL warnings for .NET trimming compatibility?

The best way to systematically resolve IL warnings for .NET trimming compatibility is to enable AOT analysis, build to collect all warnings like IL2067 and IL3050, and apply targeted fixes using annotations and refactoring strategies.