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.
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<System.__Canon,System.__Canon>)
...
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
Show a lot of notifications while the app is under memory pressure.
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
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 returns0,while the same command for Microsoft.InteractiveExperiences.Projection.dll returns
1953.