Skip to content

[Native AOT] v1.5.0-preview1 crashes when creating the column filter flyout #422

Description

@HenryWu01

Description:

WinUI.TableView v1.5.0-preview1 throws a XamlParseException when the column options/filter flyout is created in a Native AOT WinUI 3 application.

The exception is:

Cannot add instance of type 'Microsoft.UI.Xaml.Controls.MenuFlyoutItem'
to a collection of type
'Windows.Foundation.Collections.IVector`1<Microsoft.UI.Xaml.Controls.MenuFlyoutItemBase>'.
[Line: 0 Position: 0]

This appears to originate from TableViewFilterMenuFlyout.Items, which is declared as IList<MenuFlyoutItemBase>, while TableViewColumnHeader.xaml populates it with derived MenuFlyoutItem and MenuFlyoutSeparator instances. Under CsWinRT/Native AOT, the property is projected as IVector<MenuFlyoutItemBase>, and inserting the derived XAML objects fails during flyout creation.

This is different from the missing menu bindings discussed in #140: v1.5.0-preview1 gets past those binding issues, but the new filter flyout collection itself fails to materialize.

Steps to Reproduce:

  1. Create a packaged WinUI 3 application targeting .NET 10.

  2. Enable Native AOT:

    <PublishAot>true</PublishAot>
  3. Reference WinUI.TableView v1.5.0-preview1.

  4. Add a TableView with at least one bound column and leave column sorting/filtering enabled.

  5. Run the application and open a column header's options/filter menu.

  6. Observe the XamlParseException shown above.

A minimal table declaration is sufficient:

<tv:TableView ItemsSource="{x:Bind ViewModel.Items}"
              AutoGenerateColumns="False">
    <tv:TableView.Columns>
        <tv:TableViewTextColumn Header="Name"
                                Binding="{Binding Name}" />
    </tv:TableView.Columns>
</tv:TableView>

Expected behavior:

The column options/filter flyout should open and display its menu items without throwing an exception in a Native AOT application.

Screenshots:

Not applicable. The runtime exception and relevant type information are included above.

Environment:

  • Package Version: 1.5.0-preview1
  • WinAppSDK Version: host application 2.2.0; also reproduced after aligning the host to the WinAppSDK 1.8 line used by the package
  • Target framework: net10.0-windows10.0.22621.0
  • Runtime identifier: win-x64
  • Deployment: packaged MSIX
  • Native AOT: enabled

Contribution:

  • I am willing to submit a PR to fix this issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions