microsoft / microsoft/microsoft-ui-xaml

Accessing NonClientRegionsChangedEventArgs.ChangedRegions with AOT enabled causes NotSupportedException

Open
#10,835 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area-AOT area-TitleBar bug team-Core
Dominant language
C++
Stars
8.4k
Forks
942
Avg merge
2d 7h
Merged PRs (30d)
105

Description

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?
  • Non-client regions set by InputNonClientPointerSource.SetRegionRects will become 0×0 rects unexpectedly, for example, when the title bar area set by Window.SetTitleBar and InputNonClientPointerSource.SetRegionRects with NonClientKind.Caption dragged and clicked. It is also mentioned at #10379 . Handling InputNonClientPointerSource.RegionsChanged event is a feasible way to remedy this issue.
  • NativeAOT is a good feature.
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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue in a C# WinUI 3 project using the Native AOT setting, then follow the InputNonClientPointerSource.RegionsChanged handler and NonClientRegionsChangedEventArgs.ChangedRegions access described here. Investigate the array marshalling path for NonClientRegionKind; done means accessing ChangedRegions causes no NotSupportedException under Native AOT and the existing behavior remains intact without it.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, csharp
Domain
desktop
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.