-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Android 9] System.InvalidOperationException: Sequence contains no elements #4715
Comments
I was reading the source code here...
Wouldn't it be better to perform a check for elements before calling Last() on _navModel.Roots ? |
Actualy I'm trying to fix all navigations crashs on Android from all the stacktraces given by AppCenter for my apps. The only one I can't reproduce is a crash very similar to yours. System.InvalidOperationException: Sequence contains no elements
at System.Linq.Enumerable.Last[TSource] (System.Collections.Generic.IEnumerable`1[T] source) <0xc2103dc8 + 0x00054> in <20db64d8ddaf497798aac65c818abb6f>:0
at Xamarin.Forms.NavigationPage+<Xamarin-Forms-INavigationPageController-RemoveAsyncInner>d__69.MoveNext () <0xc1cd8adc + 0x002b3> in <2213e65041254f04b27ae6e57d256a86>:0
at Xamarin.Forms.NavigationPage+<PopAsyncInner>d__68.MoveNext () <0xc1cd8824 + 0x001e3> in <2213e65041254f04b27ae6e57d256a86>:0
at Xamarin.Forms.NavigationPage+<PopAsync>d__45.MoveNext () <0xc1cd78ec + 0x0038f> in <2213e65041254f04b27ae6e57d256a86>:0 I don't think that perform a check is the solution, it seems that the underlying state of the navigation stack got corrupt and in this case I think it must throw an exception. I will continue to debug the framework source code to to see if I can reproduce it. Personally, I migrated from Xamarin 2.5.0 which have less issues in this area. |
@tonholis Does your application use any other packages (other than Xamarin.Forms)? E.g., Prism, or MvvmCross? If so, could you list the versions you are using? |
If it helps here goes my current scenario. What I do is when the user puts the app in background (App.OnSleep) I do navigate to another page (e.g. a StandBy page). And because I use Prism + XF, I navigate using a slash like "/StandbyPage" to reset the stack.
I did the same. I migrated from XF 2.5.0.121934 then I noticed that error. |
There's no check there because a nav model with no elements in it shouldn't be handling a back button press in the first place. So somehow we're getting into an invalid navigation state. You mention that you do some navigation when the app goes to sleep - do you handle Resume at all? Also, in your "steps to reproduce" you don't list any interaction with the Back button - did the user who described the issue mention anything about trying to navigate Back after the app resumed? |
Got it. Yes, I handle the OnResume so the user can be directed to another screen.
That's right. There's no interaction with the back button. The steps that generated that error is exactly as described. I wonder if there's something wrong with Prism 7.1.0.431... I'll test other versions of Prism in combination with XF 3.4.0.1008975. |
How are you handling it? Does the app immediately navigate to another page with Prism? And what does the StandBy page do? |
I do something like this:
|
@tonholis I'm thinking that in the case where the user is backgrounding the app it is destroying the activity for them and then when it resumes Prism thinks the navigation stack is still there but in your OnCreate you are probably recreating the forms app from start so there is no stack? Prism is trying to navigate to the Uri you have indicated so it tries to go back but there is in fact no back stack. On lower end devices (or devices with low memory) when you background the app it will destroy the main activity and then recreate it when you resume. Which makes for different behavior with resume depending on the device I would try utilizing OnDestroy to see if the activity is destroyed and then also inside OnCreate check if the OnCreate is being called for a second time because the Activity was destroyed vs being called the first time when the app is loaded You can try creating an emulator with very little memory or find a cheap Android Device |
@tonholis Since we haven't heard from you in more than 30 days, we hope this issue is no longer affecting you. If it is, please reopen this issue and provide the requested information so that we can look into it further. Thank you! |
I have a Xamarin.Forms app and since upgrading to 3.4.0.1009999 I have noticed the following error In AppCenter MainActivity.OnBackPressed ()
Is there a fix for this in a later version or a work around we can use? |
Anybody there..? |
@AdamBowler @PaulsonMac This is a closed issue, and also the problem you are reporting seems to be unrelated to the original issue. If you are having problems with OnBackPressed, please open a separate GitHub issue. |
Hi @hartez, I'll try to open a new issue |
But I have the same issue - this occurs in many devices not just One plus and also in different android versions not just Android 9 |
@samhouts @jamesmontemagno
|
@georgethms10 Did you found a solution for this? |
Description
I upgraded an app to use the latest version of Xamarin.Forms and I caught the error described here. I couldn't reproduce it on my development device (Huawei CAN-L01 / Android 6.0).
A user which noticed the crash explained to me that he opens the app, put it in background and open it again. So it happens when a user resumes the app.
Steps to Reproduce
Expected Behavior
The app should resume successfully.
Actual Behavior
It crashes when a user resumes the app on a Oneplus 6 (A6003) with Android 9
Basic Information
Screenshots
The text was updated successfully, but these errors were encountered: