Skip to content

Accessing NonClientRegionsChangedEventArgs.ChangedRegions with AOT enabled causes NotSupportedException #10835

@SuGar0218

Description

@SuGar0218

Describe the bug

When NativeAOT is enabled, accessing NonClientRegionsChangedEventArgs.ChangedRegions in my InputNonClientPointerSource.RegionsChanged event handler, it throws System.NotSupportedException with message "Cannot handle array marshalling for non blittable type 'Microsoft.UI.Input.NonClientRegionKind'.". But it works properly without NativeAOT.

Why is this important?

Steps to reproduce the bug

  1. Create a new C# WinUI 3 project.
  2. Enable "Publish Native AOT" in the project property settings.
  3. Handle InputNonClientPointerSource.RegionsChanged event and access NonClientRegionsChangedEventArgs.ChangedRegions.
public sealed partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
        ExtendsContentIntoTitleBar = true;
        _inputNonClientPointerSource = InputNonClientPointerSource.GetForWindowId(AppWindow.Id);
        _inputNonClientPointerSource.RegionsChanged += OnNonClientRegionsChanged;
    }

    private void OnNonClientRegionsChanged(InputNonClientPointerSource sender, NonClientRegionsChangedEventArgs args)
    {
        NonClientRegionKind[] changedRegions = args.ChangedRegions;
    }

    private readonly InputNonClientPointerSource _inputNonClientPointerSource;
}

Actual behavior

System.NotSupportedException is thrown at NonClientRegionKind[] changedRegions = args.ChangedRegions with message: "Cannot handle array marshalling for non blittable type 'Microsoft.UI.Input.NonClientRegionKind'".

Expected behavior

Cause no exceptions.

Screenshots

Image

NuGet package version

WinUI 3 - Windows App SDK 1.8.1: 1.8.250916003

Windows version

Windows 11 (24H2): Build 26100

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingneeds-triageIssue needs to be triaged by the area owners

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions