WinUI 3 Unpackaged app crashed when open the context menu
See original GitHub issueDescribe the bug
My WinUI 3 Unpackaged app crashed when i right clicked on the tray icon.
I did not add a icon file, but i think it doesn’t matter, because the sample works perfectly after i delete its icon file and related statements in xaml code.
There wasn’t any exception message shown after the crash. The only message i got is the exit code : 3221226107 (0xc000027b).
Steps to reproduce the bug
- Install the NuGet package.
- Add these codes: In MainWindow.xaml
<Window xmlns:controls="using:AutoDL.Controls">
<Grid>
<!--Other Codes-->
<controls:TrayIconContextMenu/>
</Grid>
</Window>
In TrayIconContextMenu.xaml
<UserControl
x:Class="AutoDL.Controls.TrayIconContextMenu"
xmlns:tb="using:H.NotifyIcon">
<UserControl.Resources>
<XamlUICommand
x:Key="ShowHideWindowCommand"
ExecuteRequested="ShowHideWindowCommand_ExecuteRequested"
Label="Show/Hide Window"
Description="Show/Hide Window">
<XamlUICommand.IconSource>
<SymbolIconSource Symbol="OpenPane"/>
</XamlUICommand.IconSource>
<XamlUICommand.KeyboardAccelerators>
<KeyboardAccelerator
Key="S"
Modifiers="Control"
/>
</XamlUICommand.KeyboardAccelerators>
</XamlUICommand>
<XamlUICommand
x:Key="ExitApplicationCommand"
ExecuteRequested="ExitApplicationCommand_ExecuteRequested"
Label="Exit"
Description="Exit">
<XamlUICommand.IconSource>
<SymbolIconSource Symbol="ClosePane" />
</XamlUICommand.IconSource>
<XamlUICommand.KeyboardAccelerators>
<KeyboardAccelerator
Key="E"
Modifiers="Control"
/>
</XamlUICommand.KeyboardAccelerators>
</XamlUICommand>
<MenuFlyout
x:Key="TrayContextFlyout"
AreOpenCloseAnimationsEnabled="False">
<MenuFlyoutItem Command="{StaticResource ShowHideWindowCommand}" />
<MenuFlyoutSeparator />
<MenuFlyoutItem Command="{StaticResource ExitApplicationCommand}" />
</MenuFlyout>
</UserControl.Resources>
<tb:TaskbarIcon
x:Name="TrayIcon"
ToolTipText="AutoDL"
ContextFlyout="{StaticResource TrayContextFlyout}"
NoLeftClickDelay="True"
ContextMenuMode="SecondWindow"
LeftClickCommand="{StaticResource ShowHideWindowCommand}"
/>
</UserControl>
In TrayIconContextMenu.cs
public sealed partial class TrayIconContextMenu : UserControl
{
public TrayIconContextMenu()
{
this.InitializeComponent();
}
public void ShowHideWindowCommand_ExecuteRequested(object? _, ExecuteRequestedEventArgs args)
{
var window = UIHelper.MainWindow;
if (window == null)
{
return;
}
if (window.Visible)
{
window.Hide();
}
else
{
window.Show();
}
}
public void ExitApplicationCommand_ExecuteRequested(object? _, ExecuteRequestedEventArgs args)
{
TrayIcon.Dispose();
UIHelper.MainWindow.Close();
}
}
- Run the app.
- Right click on the tray icon.
Expected behavior
It should show a fluent design context menu after i right clicked it.
Screenshots
No response
NuGet package version
2.0.64
Platform
WinUI
IDE
Visual Studio 2022
Windows Version
Windows 11
WindowsAppSDK Version
1.1
WindowsAppSDK Type
Unpackaged
Manifest
No response
Additional context
No response
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:9 (4 by maintainers)
Top Results From Across the Web
WinUI 3 App Runs on Development Machine, Crashes ...
I have a WinUI3/Windows App executable which runs fine on my development machine. After it's signed it can be installed on the development ......
Read more >WinUI 3 app crashed when deployed to the store
Since I deploy my app to the store I think it goes under packaged. As far as I can see this issue only...
Read more >We're the Windows Developer team, and we're back to talk ...
It sounds like a silly test but if you right click on the Start Button and hit 'Esc' when the context menu is...
Read more >Fix Microsoft Store Crashing on Windows 10
In the search field, type in “WSReset.exe” and right-click on the application from the search results. Click Run as administrator from the context...
Read more >Is the Windows Settings App Crashing? Try These Fixes
Click on the Windows icon on your taskbar and right-click on the Settings icon. · Choose App settings from the context menu. ·...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Now I know the reason for this exception. My app calls utility class code on the Activated event to set the app background to the Mica material. After I delete the relevant code, the menu will appear normally after right-clicking the tray icon. These are the relevant codes:
The above code borrows the sample code in WinUI 3 Gallery.
According to Microsoft Docs page, using Mica material requires Microsoft.WindowsAppSDK NuGet Package. This is more troublesome on non-WinUI projects that are not packaged.