From 9a9424a975109095d748ad2732b51a9e9e744166 Mon Sep 17 00:00:00 2001 From: Arjun Balgovind <32061677+arjunbalgovind@users.noreply.github.com> Date: Tue, 20 Oct 2020 12:50:04 -0700 Subject: [PATCH] Add null check for WindowsXamlHost_ChildChanged handler (#7426) --- .../MainWindow.xaml.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/core/Microsoft.PowerToys.Settings.UI.Runner/MainWindow.xaml.cs b/src/core/Microsoft.PowerToys.Settings.UI.Runner/MainWindow.xaml.cs index ff477163a5..38c02e694a 100644 --- a/src/core/Microsoft.PowerToys.Settings.UI.Runner/MainWindow.xaml.cs +++ b/src/core/Microsoft.PowerToys.Settings.UI.Runner/MainWindow.xaml.cs @@ -30,6 +30,12 @@ namespace Microsoft.PowerToys.Settings.UI.Runner private void WindowsXamlHost_ChildChanged(object sender, EventArgs e) { + // If sender is null, it could lead to a NullReferenceException. This might occur on restarting as admin (check https://github.com/microsoft/PowerToys/issues/7393 for details) + if (sender == null) + { + return; + } + // Hook up x:Bind source. WindowsXamlHost windowsXamlHost = sender as WindowsXamlHost; ShellPage shellPage = windowsXamlHost.GetUwpInternalObject() as ShellPage;