NavigationPageRenderer - OnAttachedToWindow - Sequence contains no elements

We changed some code and now the Android app crashes on startup. This is what I got from the log:

Time Device Name Type PID Tag Message
07-26 10:14:26.356 LGE Nexus 5X Info 27331 MonoDroid System.InvalidOperationException: Sequence contains no elements
at System.Linq.Enumerable.Last[TSource] (System.Collections.Generic.IEnumerable`1[T] source) [0x00010] in :0
at Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer.OnAttachedToWindow () [0x00011] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\AppCompat\NavigationPageRenderer.cs:211
at Android.Views.View.n_OnAttachedToWindow (System.IntPtr jnienv, System.IntPtr native__this) [0x00008] in <9ab9faae1b4b4f0da28e7c4ac61e2c78>:0
at (wrapper dynamic-method) System.Object:d392ac44-8ad7-4f92-9fdf-b7aceefc1fe7 (intptr,intptr)

I can see the code here:
https://github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.Platform.Android/AppCompat/NavigationPageRenderer.cs

But, I'm powerless to stop the bug or detect why it is occurring. Could someone at Xamarin please put a better validation error message in this method? Or, could someone please recommend a work around? This code works fine on UWP.

Answers

  • ivkuivku Member

    Check if App.MainPage property is set before passing an instance to LoadApplicaiton in MainActivity. By the way if MainPage is a NavigationPage with null as root page you can experience the issue.

Sign In or Register to comment.