microsoft / microsoft/microsoft-ui-xaml
Accessing NonClientRegionsChangedEventArgs.ChangedRegions with AOT enabled causes NotSupportedException
Nobody has claimed this yet.
- 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.SetRegionRectswill become 0×0 rects unexpectedly, for example, when the title bar area set byWindow.SetTitleBarandInputNonClientPointerSource.SetRegionRectswithNonClientKind.Captiondragged and clicked. It is also mentioned at #10379 . HandlingInputNonClientPointerSource.RegionsChangedevent is a feasible way to remedy this issue. - NativeAOT is a good feature.
Steps to reproduce the bug
- Create a new C# WinUI 3 project.
- Enable "Publish Native AOT" in the project property settings.
- Handle
InputNonClientPointerSource.RegionsChangedevent and accessNonClientRegionsChangedEventArgs.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
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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