Skip to content

XAML resource trimming keeps controls that are only type-checked #26048

Open

Description

@MartinZikmund

Current behavior 🐛

With UnoXamlResourcesTrimming, LinkerHintGeneratorTask marks a DependencyObject type available whenever its TypeDef survives a linker pass. Any is check, cast or field of that type is enough to keep the TypeDef, so the type's hint becomes true. The bindable metadata then constructs it, which keeps its whole implementation.

In a blank unoapp (WebAssembly, Release, trimming on), framework code such as TextCore.IsTextControl and UIElement.OnContextRequestedCore does is RichEditBox. That keeps RichEditBox, its RTF codec and System.Text.Encoding.CodePages, plus ~110 other controls the app never creates (TextBox, ComboBox, MenuFlyout, ContentDialog, …).

Expected behavior 🎯

A control nothing can construct is trimmed together with its styles and metadata.

How to reproduce it (as minimally and precisely as possible) 🔬

  1. dotnet new unoapp -preset blank -platforms wasm
  2. Publish Release with -p:UnoXamlResourcesTrimming=true -p:_TrimmerDumpDependencies=true.
  3. In obj/.../linked/linker-dependencies.xml, Blank.MetadataBuilder_N::Build reaches RichEditBox::.ctor().

Workaround 🛠️

None.

Affected platforms 📱💻🖥️

WebAssembly, and any trimmed head that uses XAML resource trimming.

Uno.Sdk version (and other relevant versions) 📦

Uno.Sdk 7.0.0-dev.132 (Uno.WinUI 7.0.0-dev.2556), .NET SDK 10.0.401.

Anything else we need to know? 💬

Requiring a kept instance constructor (or an abstract type) saves 822 KB brotli on the blank app, and 600 KB on an app using 20 common controls, which renders pixel-identically.

Activity

  1. self-assigned this
    on Nov 4, 2026
  2. added
    kind/bug
    platform/wasm 🌐
    area/performance 📈
    area/xaml-trimming
    on Nov 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/performance 📈area/xaml-trimmingkind/bugplatform/wasm 🌐

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions