microsoft / microsoft/WindowsAppSDK
ThemeSettings Crashing application
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 4.7k
- Forks
- 471
- Avg merge
- 3d 13h
- Merged PRs (30d)
- 28
Description
Describe the bug
For some reason when I use ThemeSettings to watch the Changed event, the application crashes with an internal error from SDK.
It happens in two scenarios:
1 - When I use ThemeSettings like a local variable
2 - When I use ThemeSettings like a global variable in a single instance class
Steps to reproduce the bug
I create an app with two Pages and move back and forth between them.
First scenario you can use it like that in the Loaded event in the second Page.
if (this.XamlRoot != null && this.XamlRoot.ContentIslandEnvironment != null)
{
WindowId myWindowId = this.XamlRoot.ContentIslandEnvironment.AppWindowId;
var _themeSettings = ThemeSettings.CreateForWindowId(myWindowId);
if (_themeSettings != null)
{
_themeSettings.Changed += ThemeSettings_Changed;
}
}
In some moments the App Crashes...
The second scenario just replaces var _themeSettings for a global variable and moves the code to a singleton class. Both crashes the same way.
I suppose it can happen because the Changed event isn't explicitly unsubscribed... But I believe it's an unhandled exception in the SDK source code.
To solve the problem by now, I'm checking if _themeSettings is not null before CreateForWindowId and Unbscribe the Changed event in the Unload page Event, but I'm not sure if other crashes can reside.
Expected behavior
Do not crash the app.
Screenshots
No valuable information actually.
NuGet package version
WinUI 3 - Windows App SDK 1.6.3: 1.6.241114003
Windows version
Windows 11 (22H2): Build 22621
Additional context
No response
Contributor guide
No contributing guide indexed for this repository
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
Start by reproducing the two-page WinUI 3 application with Windows App SDK 1.6.3 using the ThemeSettings.CreateForWindowId call and Changed event subscription shown in the issue. Compare the local-variable and singleton cases, capture the internal SDK crash, and consider the issue complete when the crash is reproducible with a narrowed cause and a confirmed fix or clear SDK diagnosis.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- desktop
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100