Skip to content

Add Native AOT compatibility - #5156

Merged
Denis Voituron (dvoituron) merged 6 commits into
microsoft:dev-v5from
JamesNK:aot-compatibility
Aug 17, 2026
Merged

Denis Voituron (dvoituron) merged 6 commits into
microsoft:dev-v5from
JamesNK:aot-compatibility

Conversation

@JamesNK

Copy link
Copy Markdown
Member

Pull Request

📖 Description

Adds Native AOT compatibility declarations and removes unannotated trimming, single-file, and AOT analyzer warnings from the core Components package and the Icons and Emoji package graphs.

The core changes:

  • Replace runtime generic reflection in PropertyColumn formatting and FluentField field identifier creation.
  • Use source-generated System.Text.Json metadata for theme serialization and deserialization.
  • Use AOT-safe enum enumeration and assembly-name inspection in icon and emoji discovery.
  • Set IsAotCompatible on every shipped Core, Icons, and Emoji assembly.
  • Build the Icons and Emoji package graphs in the existing warning-as-error CI workflow.

The reflection-based GetInstance and GetAll* asset discovery APIs retain their existing RequiresUnreferencedCode contracts. Direct references to generated icon and emoji types are AOT-safe.

🎫 Issues

None.

👩‍💻 Reviewer Notes

The main review areas are the formatter behavior in PropertyColumn, expression parsing in FluentField, and preservation of the flat theme JSON wire format through source generation.

📑 Test Plan

  • dotnet test tests/Core/Components.Tests.csproj --configuration Debug --no-restore --no-build
    • 3,821 passed, 0 failed
  • dotnet build src/Core/Microsoft.FluentUI.AspNetCore.Components.csproj --configuration Release -warnaserror
    • net8.0, net9.0, and net10.0; 0 warnings, 0 errors
  • dotnet build src/Assets/FluentUI.Icons/Components.Icons.Package.csproj --configuration Debug
    • 0 warnings, 0 errors
  • dotnet build src/Assets/FluentUI.Emojis/Components.Emoji.Package.csproj --configuration Debug
    • 0 warnings, 0 errors
  • Published and ran an isolated .NET 8 win-x64 Native AOT executable with warnings as errors. It successfully used FluentButton, concrete generated Icon and Emoji types, and a Theme JSON round trip.

✅ Checklist

General

  • I have added tests for my changes.
  • I have tested my changes.
  • I have updated the project documentation to reflect my changes.
  • I have read the CONTRIBUTING documentation and followed the standards for this project.

Component-specific

  • I have added a new component
  • I have added Unit Tests for my new component
  • I have modified an existing component
  • I have validated the Unit Tests for an existing component

⏭ Next Steps

None.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds Native AOT compatibility declarations and removes AOT-unfriendly patterns across Fluent UI Blazor’s Core, Icons, and Emoji packages, primarily by replacing runtime generic reflection and by switching theme JSON (de)serialization to source-generated System.Text.Json metadata.

Changes:

  • Declares IsAotCompatible on shipped Core/Icons/Emoji assemblies and expands CI to build the Icons/Emoji package graphs with warnings-as-errors.
  • Replaces reflection-based formatting in PropertyColumn and reflection-based FieldIdentifier.Create invocation in FluentField.
  • Introduces a source-generated JsonSerializerContext for theme dictionary JSON round-tripping, and updates theme (de)serialization to use it.

Reviewed changes

Copilot reviewed 23 out of 23 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/Core/Microsoft.FluentUI.AspNetCore.Components.csproj Marks the Core components assembly as AOT-compatible.
src/Core/Components/Theme/Styles/ThemeJsonSerializerContext.cs Adds source-generated JSON metadata context for theme dictionary serialization.
src/Core/Components/Theme/Styles/ThemeExtensions.cs Switches Theme JSON (de)serialization to the source-generated context.
src/Core/Components/Icons/IconsExtensions.cs Uses AOT-safe enum enumeration and assembly-name matching for icon discovery/loading.
src/Core/Components/Field/FluentField.razor.cs Removes reflection-based FieldIdentifier.Create invocation and replaces it with expression parsing.
src/Core/Components/Emojis/EmojiExtensions.cs Uses assembly-name matching via AssemblyName.Name for emoji discovery/loading.
src/Core/Components/DataGrid/Columns/PropertyColumn.cs Replaces runtime generic reflection formatter creation with an interface-based formatter path.
src/Assets/FluentUI.Icons/Icons/Regular/Icons.Regular.csproj Marks Icons.Regular as AOT-compatible.
src/Assets/FluentUI.Icons/Icons/Light/Icons.Light.csproj Marks Icons.Light as AOT-compatible.
src/Assets/FluentUI.Icons/Icons/Filled/Icons.Filled.csproj Marks Icons.Filled as AOT-compatible.
src/Assets/FluentUI.Icons/Icons/Color/Icons.Color.csproj Marks Icons.Color as AOT-compatible.
src/Assets/FluentUI.Icons/Components.Icons.Package.csproj Marks the Icons package graph root as AOT-compatible.
src/Assets/FluentUI.Emojis/Emojis/TravelPlaces/Emoji.TravelPlaces.csproj Marks Emojis.TravelPlaces as AOT-compatible.
src/Assets/FluentUI.Emojis/Emojis/Symbols/Emoji.Symbols.csproj Marks Emojis.Symbols as AOT-compatible.
src/Assets/FluentUI.Emojis/Emojis/SmileysEmotion/Emoji.SmileysEmotion.csproj Marks Emojis.SmileysEmotion as AOT-compatible.
src/Assets/FluentUI.Emojis/Emojis/PeopleBody/Emoji.PeopleBody.csproj Marks Emojis.PeopleBody as AOT-compatible.
src/Assets/FluentUI.Emojis/Emojis/Objects/Emoji.Objects.csproj Marks Emojis.Objects as AOT-compatible.
src/Assets/FluentUI.Emojis/Emojis/FoodDrink/Emoji.FoodDrink.csproj Marks Emojis.FoodDrink as AOT-compatible.
src/Assets/FluentUI.Emojis/Emojis/Flags/Emoji.Flags.csproj Marks Emojis.Flags as AOT-compatible.
src/Assets/FluentUI.Emojis/Emojis/AnimalsNature/Emoji.AnimalsNature.csproj Marks Emojis.AnimalsNature as AOT-compatible.
src/Assets/FluentUI.Emojis/Emojis/Activities/Emoji.Activities.csproj Marks Emojis.Activities as AOT-compatible.
src/Assets/FluentUI.Emojis/Components.Emoji.Package.csproj Marks the Emoji package graph root as AOT-compatible.
.github/workflows/build-core-lib.yml Adds Icons/Emoji package graph builds to the existing warning-as-error workflow.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@dvoituron
Denis Voituron (dvoituron) merged commit 9ca6a84 into microsoft:dev-v5 Aug 17, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants