Regression (a behavior that used to work and stopped working in a new release)
(I think...)
If an app calls Show() on an InAppNotification on Page 1, but the user has navigated to Page 2, the app will crash with an unhandled exception that cannot be handled by the app:
System.ArgumentException: The parameter is incorrect.
element
at Windows.UI.Xaml.Automation.Peers.FrameworkElementAutomationPeer.CreatePeerForElement(UIElement element)
at Microsoft.Toolkit.Uwp.UI.Controls.InAppNotification.OpenAnimationTimer_Tick(Object sender, Object e)
The exception should be handled by the InAppNotification class.
or
Nuget Package(s): Microsoft.Toolkit.Uwp.UI.Controls
Package Version(s): 5.1.1
Windows 10 Build Number:
- [ ] Fall Creators Update (16299)
- [ ] April 2018 Update (17134)
- [ ] October 2018 Update (17763)
- [x] Insider Build (18362.53)
App min and target version:
- [x] Fall Creators Update (16299)
- [x] April 2018 Update (17134)
- [ ] October 2018 Update (17763)
- [ ] Insider Build (xxxxx)
Device form factor:
- [x] Desktop
- [ ] Mobile
- [ ] Xbox
- [ ] Surface Hub
- [ ] IoT
Visual Studio
- [ ] 2017 (version: )
- [ ] 2017 Preview (version: )
- [x] 2019 (16.0.1)
Thanks @mfeingol for the report. Do you happen to have an idea of which version it used to work on before you upgraded?
@Odonno any thoughts on this? Would you have time to take a look?
To be honest, I don't know that this ever worked. But one day I got a crash report for my app pointing at OpenAnimationTimer_Tick, and I managed to reproduce it in this way.
Either way, if the XAML engine is throwing ArgumentException for a reason (page is no longer current), and there's no way for you to determine that, you may just want to catch the exception in OpenAnimationTimer_Tick and avoid calling AutomateTextNotification.
I can try to reproduce this error but first I want to ask why not using an App Shell to display your notifications on every screen?
I am not sure if we can verify if the current page == page to display notifications. It can be better than catching the exception in my opinion.
@Odonno: just so I understand, what do you mean precisely by using an App Shell?
@mfeingol Having a main Frame with an empty page (or whatever you need in you shell), and then every page in your application is inside a nested Frame of this page, the shell of your entire app.
So that way you can display notifications everywhere at any time. I know some people usually do that to create an app menu, to set the background color and to handle global notifications.
Yep, I can confirm something like this will work in my ShellPage:
<Grid>
<Frame x:Name="ShellFrame" />
+ <controls:InAppNotification x:Name="Notification" />
</Grid>
That said, I'd still recommend catching that exception. I still have cases where I display popups that have their own embedded notifications, and I'm afraid I might run into the same problem if the user closes the popup and triggers a race condition.
Any updates on this? It crashes for me when dismissing a InAppNotification
Well, I would like to start this but there is already a fix waiting for review here #2937
If I work on 2 PRs simultaneously, I am not sure of the final result. I prefer to do them sequentially.
You can probably use different branches.
@tipa: the workaround mentioned above doesn't work for you?
My app is a one-page app already and for me the crash happens on dismissing and not on showing, so the causes might be slightly different. But catching the exception should resolve my problem as well.
This happens only on latest version of Windows 10. I have a old desktop on 17763.557 and it does not throw an exception on that. Something in OS Changed?
Thanks for the info @avknaidu. I'm on a newer OS build, so I'm going to test this out now.
I've confirmed this bug on 6.0.0. I'll work on a fix.
Most helpful comment
I've confirmed this bug on 6.0.0. I'll work on a fix.