Skip to content

[Shortcut Guide] Guard against null AppWindow in SetWindowPosition#48870

Draft
niels9001 wants to merge 1 commit into
mainfrom
niels9001-fix-shortcut-guide-setwindowposition-nre
Draft

[Shortcut Guide] Guard against null AppWindow in SetWindowPosition#48870
niels9001 wants to merge 1 commit into
mainfrom
niels9001-fix-shortcut-guide-setwindowposition-nre

Conversation

@niels9001

Copy link
Copy Markdown
Collaborator

Summary

Fixes the residual NullReferenceException in MainWindow.SetWindowPosition() reported in #48773 (seen on Windows 10, even after the 0.100.1 hotfix #48481).

Background

#48481 stopped the original hard crash by adding a try/catch and null-guarding App.TaskBarWindow?.AppWindow. But a second NRE remained. From the reporter's 0.100.1 log:

[Error] MainWindow.xaml.cs::SetWindowPosition::286  Failed to set Shortcut Guide window position; keeping previous layout.
System.NullReferenceException
   at WinUIEx.WindowManager.get_Height()
   at WinUIEx.WindowManager.set_MaxHeight(Double value)
   at ShortcutGuide.MainWindow.SetWindowPosition()

Root cause

Selecting the Windows section (the only common one carrying the <TASKBAR1-9> section) runs App.TaskBarWindow.Hide() → Activate() → BringToFront(). That reentrancy re-enters SetWindowPosition() while the main window's own AppWindow is transiently null. The earlier fix only guarded the taskbar window's AppWindow, not the main window's. The first size access in the method (MaxHeight = newHeight) makes WinUIEx read get_Height() on the null AppWindow → NRE. The exception is now caught (post-#48481), so it no longer hard-crashes, but the overlay is left mispositioned and the section appears broken on Windows 10.

Change

Early-return from SetWindowPosition() when the window's own AppWindow is null. This is safe: a later AppWindow.Changed / Activated event reruns the positioning once the window settles, so the final layout is still applied — only the bogus reentrant pass is dropped. The existing try/catch remains as a backstop.

Validation

  • ShortcutGuide.Ui builds clean (x64 Release, exit 0).
  • Opened as draft for manual repro/validation on a Windows 10 multi-monitor setup.

Notes

The long-term cleanup is the dual-window → single-overlay rewrite in #48683, which removes this code path entirely. This is the small, low-risk hotfix for the 0.100.x line.

…48773)

When the Windows section is selected, the Hide -> Activate -> BringToFront
reentrancy can re-enter SetWindowPosition while the main window's own
AppWindow is transiently null. The first WinUIEx size access (MaxHeight ->
get_Height) then dereferences the null AppWindow and throws a
NullReferenceException, leaving the overlay mispositioned on Windows 10.

Skip the positioning pass when AppWindow is null; a later AppWindow.Changed
or Activated event reruns it once the window settles.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot added the Product-Shortcut Guide Refers to the Shortcut Guide PowerToy label Jun 25, 2026
@niels9001 niels9001 added the Hot Fix Items we will product an out-of-band release for label Jun 25, 2026
@niels9001 niels9001 requested a review from noraa-junker June 25, 2026 16:17
@niels9001 niels9001 removed the Hot Fix Items we will product an out-of-band release for label Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Product-Shortcut Guide Refers to the Shortcut Guide PowerToy

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant