microsoft / microsoft/WindowsAppSDK
Crash on building a notification
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
Our app randomly crashes when it creates notifications under memory pressure.
Possible reason is that AppNotifications.Builder RCW is finalized while the function call is still happening.
It can happen because these projections are generated without `GC.KeepAlive`.
Microsoft.Windows.AppNotifications.Builder.Projection.dll
Microsoft.Windows.AppNotifications.Projection.dll
It was addressed in PR https://github.com/microsoft/CsWinRT/pull/1848/changes, but the assemblies above still do not have that guard.
Some crash details
```
CoreCLR Version: 10.0.726.21808
.NET Version: 10.0.7
Description: The process was terminated due to an unhandled exception.
Stack:
at ABI.Microsoft.Windows.AppNotifications.Builder.IAppNotificationBuilderMethods.BuildNotification(WinRT.IObjectReference)
at Toast.ToastNotificationService.ShowChatNotification(Toast.ChatNotification)
at System.Reactive.Linq.ObservableImpl.WithLatestFrom`3+_+FirstObserver[[System.ValueTuple`2[[System.__Canon, System.Private.CoreLib, Version=10.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=10.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=10.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.ValueTuple`2[[System.Nullable`1[[_Chats.ChatId, phone, Version=21.0.996.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=10.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Boolean, System.Private.CoreLib, Version=10.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=10.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Reactive.Unit, System.Reactive, Version=6.1.0.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263]].OnNext(System.ValueTuple`2)
...
Faulting application name: phone.exe, version: 1.0.996.0, time stamp: 0x69e20000
Faulting module name: coreclr.dll, version: 10.0.726.21808, time stamp: 0x69e279e8
Exception code: 0xc0000005
Fault offset: 0x000000000035699f
Faulting process id: 0x1978
Faulting application start time: 0x1DCE3AE8EC0F524
Faulting application path: C:\Program Files\WindowsApps\...\phone.exe
Faulting module path: C:\Program Files\WindowsApps\...\coreclr.dll
Report Id: a52651d7-8896-493a-9c22-d32ab4b98806
Faulting package-relative application ID: App
```
### Steps to reproduce the bug
Show a lot of notifications while the app is under memory pressure.
### NuGet package version
2.4.0
### Additional stuff
I checked if there is a guard using the command
`ildasm Microsoft.Windows.AppNotifications.Builder.Projection.dll /text | find /c "System.GC::KeepAlive"` which returns `0`,
while the same command for Microsoft.InteractiveExperiences.Projection.dll returns `1953`.
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 comparing PR #1848 with Microsoft.Windows.AppNotifications.Builder.Projection.dll and Microsoft.Windows.AppNotifications.Projection.dll; the issue identifies these assemblies as missing GC.KeepAlive guards. Use ildasm with the reported command to verify the generated assemblies, then confirm notification creation remains stable under memory pressure.
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
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100