Bug 38731 - Xamarin.Forms.Platform.iOS.NavigationRenderer.GetAppearedOrDisappearedTask NullReferenceExceptionObject
Summary: Xamarin.Forms.Platform.iOS.NavigationRenderer.GetAppearedOrDisappearedTask N...
Status: RESOLVED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: iOS (show other bugs)
Version: 2.3.4
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Rui Marinho
URL:
Depends on:
Blocks:
 
Reported: 2016-02-12 21:19 UTC by Caan Mee
Modified: 2017-10-05 01:20 UTC (History)
24 users (show)

See Also:
Tags: ios crash navigation nre
Is this bug a regression?: No
Last known good build:


Attachments
Repro project from comment 5. (225.45 KB, application/x-zip-compressed)
2016-06-01 22:24 UTC, Phillip
Details
repro project (150.96 KB, application/x-zip-compressed)
2017-04-17 22:07 UTC, Jimmy [MSFT]
Details

Description Caan Mee 2016-02-12 21:19:44 UTC
The following exception occasionally occurs in my Xamarin.Insights Report.

Sadly I'm not able to reproduce it on my test devices. Eventually you guys got an idea?

System.NullReferenceExceptionObject reference not set to an instance of an object


  at Xamarin.Forms.Platform.iOS.NavigationRenderer.GetAppearedOrDisappearedTask (Xamarin.Forms.Page page) <0x101258510 + 0x00054> in <filename unknown>:0 
  at Xamarin.Forms.Platform.iOS.NavigationRenderer.RemoveViewControllers (Boolean animated) <0x101257cb0 + 0x000af> in <filename unknown>:0 
  at Xamarin.Forms.Platform.iOS.NavigationRenderer.PopViewController (Boolean animated) <0x101257c44 + 0x00017> in <filename unknown>:0 
  at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) <0x100aba118 + 0x0009b> in <filename unknown>:0 
  at MyApp.Application.Main (System.String[] args) <0x100032aa0 + 0x0001b> in <filename unknown>:0 


Using Xamarin.Forms 2.0.1
Comment 1 Michael Rumpler 2016-03-07 09:13:06 UTC
I got this exception too and the app crashed afterwards.
It occured when I had a simple NavigationPage with several other pages on the stack and I wanted to navigate back to the root by tapping on the back buttons rather fast. So I don't do any navigation programatically. The user can do that.

Here are some messages from the debug window:

2016-03-07 08:49:54.553 RoyalTSiPro[3828:25450] Unbalanced calls to begin/end appearance transitions for <_UIWaitingForRemoteViewContainerViewController: 0x7e97c1e0>.
Thread started:  #8
Thread started:  #9
2016-03-07 08:50:01.104 RoyalTSiPro[3828:25470] plugin com.apple.UIKit.fileprovider.default invalidated
2016-03-07 08:50:03.249 RoyalTSiPro[3828:25450] Unbalanced calls to begin/end appearance transitions for <_UIWaitingForRemoteViewContainerViewController: 0x7e7d3660>.
Thread started:  #10
2016-03-07 08:50:09.978 RoyalTSiPro[3828:25509] plugin com.apple.UIKit.fileprovider.default invalidated
2016-03-07 08:50:18.394 RoyalTSiPro[3828:25450] Unbalanced calls to begin/end appearance transitions for <_UIWaitingForRemoteViewContainerViewController: 0x7ef11ba0>.
2016-03-07 08:50:20.119 RoyalTSiPro[3828:25456] plugin com.apple.UIKit.fileprovider.default invalidated
Thread started: <Thread Pool> #11
2016-03-07 08:50:24.941 RoyalTSiPro[3828:25450] Unbalanced calls to begin/end appearance transitions for <_UIWaitingForRemoteViewContainerViewController: 0x7ef11ba0>.
2016-03-07 08:50:27.115 RoyalTSiPro[3828:25456] plugin com.apple.UIKit.fileprovider.default invalidated
2016-03-07 08:50:32.082 RoyalTSiPro[3828:25450] System.NullReferenceException: Object reference not set to an instance of an object
  at Xamarin.Forms.Platform.iOS.NavigationRenderer.GetAppearedOrDisappearedTask (Xamarin.Forms.Page page) [0x00018] in <filename unknown>:0 
  at Xamarin.Forms.Platform.iOS.NavigationRenderer.RemoveViewControllers (Boolean animated) [0x00048] in <filename unknown>:0 
  at Xamarin.Forms.Platform.iOS.NavigationRenderer.PopViewController (Boolean animated) [0x00000] in <filename unknown>:0 
  at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
  at UIKit.UIApplication.Main (System.String[] args, IntPtr principal, IntPtr delegate) [0x00005] in /Users/builder/data/lanes/2689/962a0506/source/maccore/src/UIKit/UIApplication.cs:77 
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Users/builder/data/lanes/2689/962a0506/source/maccore/src/UIKit/UIApplication.cs
:61 
  at RoyalMobileApps.XF.iOS.Application.Main (System.String[] args) [0x00002] in D:\RoyalFamily\RoyalMobileApps.XF\iOS\RoyalTSi\Main.cs:19 
[0:] System.NullReferenceException: Object reference not set to an instance of an object
  at Xamarin.Forms.Platform.iOS.NavigationRenderer.GetAppearedOrDisappearedTask (Xamarin.Forms.Page page) [0x00018] in <filename unknown>:0 
  at Xamarin.Forms.Platform.iOS.NavigationRenderer.RemoveViewControllers (Boolean animated) [0x00048] in <filename unknown>:0 
  at Xamarin.Forms.Platform.iOS.NavigationRenderer.PopViewController (Boolean animated) [0x00000] in <filename unknown>:0 
  at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
  at UIKit.UIApplication.Main (System.String[] args, IntPtr principal, IntPtr delegate) [0x00005] in /Users/builder/data/lanes/2689/962a0506/source/maccore/src/UIKit/UIApplication.cs:77 
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Users/builder/data/lanes/2689/962a0506/source/maccore/src/UIKit/UIApplication.cs:61 
  at RoyalMobileApps.XF.iOS.Application.Main (System.String[] args) [0x00002] in D:\RoyalFamily\RoyalMobileApps.XF\iOS\RoyalTSi\Main.cs:19 
Launched 'RoyalMobileAppsXFiOS' successfully on 'iPhone 6 iOS 9.2'...
The app has been terminated.

Notice the "Unbalanced calls to begin/end appearance transitions for <_UIWaitingForRemoteViewContainerViewController" messages before the app crashes.

I got this on both a physical iPad4 and an iPhone6 simulator. My app uses XF 2.1.0.6521.
Comment 2 Michael Rumpler 2016-03-08 15:27:35 UTC
The "Unbalanced calls to begin/end appearance transitions" was not related to the crash.
I present a UIDocumentPickerViewController on click of a ToolbarItem. When I do that without animation, then the message is gone.
Comment 3 John Hardman 2016-03-21 00:03:39 UTC
Same problem here, after upgrading NuGet packages, including upgrading XF to 2.1.0.6529 . Never seen the problem before upgrading.

[0:] Exception = System.NullReferenceException: Object reference not set to an instance of an object
  at Xamarin.Forms.Platform.iOS.NavigationRenderer.GetAppearedOrDisappearedTask (Xamarin.Forms.Page page) [0x00018] in <filename unknown>:0 
  at Xamarin.Forms.Platform.iOS.NavigationRenderer.RemoveViewControllers (Boolean animated) [0x00048] in <filename unknown>:0 
  at Xamarin.Forms.Platform.iOS.NavigationRenderer.PopViewController (Boolean animated) [0x00000] in <filename unknown>:0 
  at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
  at UIKit.UIApplication.Main (System.String[] args, IntPtr principal, IntPtr delegate) [0x00005] in /Users/builder/data/lanes/2377/73229919/source/maccore/src/UIKit/UIApplication.cs:77 
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0001c] in /Users/builder/data/lanes/2377/73229919/source/maccore/src/UIKit/UIApplication.cs:60 
  at MyAppNamespace.iOS.Application.Main (System.String[] args) [0x00032] in G:\tfs\MyApp\MyApp\MyApp.iOS\Main.cs:36 
[0:] FilePath = G:\tfs\MyApp\MyApp\MyApp.iOS\Main.cs2016-03-20 23:50:06.608 MyAppiOS[3329:1681021] Exception = System.NullReferenceException: Object reference not set to an instance of an object
  at Xamarin.Forms.Platform.iOS.NavigationRenderer.GetAppearedOrDisappearedTask (Xamarin.Forms.Page page) [0x00018] in <filename unknown>:0 
  at Xamarin.Forms.Platform.iOS.NavigationRenderer.RemoveViewControllers (Boolean animated) [0x00048] in <filename unknown>:0 
  at Xamarin.Forms.Platform.iOS.NavigationRenderer.PopViewController (Boolean animated) [0x00000] in <filename unknown>:0 
  at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
  at UIKit.UIApplication.Main (System.String[] args, IntPtr principal, IntPtr delegate) [0x00005] in /Users/builder/data/lanes/2377/73229919/source/maccore/src/UIKit/UIApplication.cs:77 
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0001c] in /Users/builder/data/lanes/2377/73229919/source/maccore/src/UIKit/UIApplication.cs:60 
  at MyAppNamespace.iOS.Application.Main (System.String[] args) [0x00032] in G:\tfs\MyApp\MyApp\MyApp.iOS\Main.cs:36
Comment 4 John Miller [MSFT] 2016-06-01 13:09:50 UTC
Would anyone be able to provide me with the project, or a sample project, that reproduces this issue so that I can investigate this further?
If possible, please zip up a minimized, runnable test case that reproduces the issue so we can run some tests. Before zipping the app, you can delete the folders listed below in all subdirectories to save space (they will be updated automatically as long as they are still referenced correctly in the solution):
 
*/bin
*/obj
*/packages
*/Components

Also, please include any steps I should take to reproduce the issue using the project. Thanks!
Comment 5 Phillip 2016-06-01 22:23:59 UTC
I have also had this exception followed by the app crashing. The replication steps are the same, by navigating back to the root by tapping on the back buttons quickly. The exception may be happening when the back button event is triggered on the same page twice.

In my project, we are customizing the back button image on iOS and the stack trace also includes the null reference exception is at UIKit.UIBarButtonItem+Callback.Call.

I am using Xamarin.Forms.1.5.1.6471 and can replicate in Xamarin.Forms.2.2.0.45

I will attach a sample project where I have replicated the exception with the following stack trace.

---------------------------------------------

Unhandled Exception:

System.NullReferenceException: Object reference not set to an instance of an object

Thread finished: <Thread Pool> #7
The thread '<Thread Pool>' (0x7) has exited with code 0 (0x0).
2016-06-02 07:57:37.348 TestApplicationiOS[179:3167] 
Unhandled Exception:
System.NullReferenceException: Object reference not set to an instance of an object
  at TestApplication.iOS.Renderers.CustomPageRenderer.<ViewWillAppear>b__0_0 (System.Object sender, System.EventArgs args) [0x00001] in C:\TestApplication\TestApplication\TestApplication.iOS\Renderers\CustomPageRenderer.cs:25 
  at UIKit.UIBarButtonItem+Callback.Call (Foundation.NSObject sender) [0x00010] in /Users/builder/data/lanes/2689/962a0506/source/maccore/src/UIKit/UIBarButtonItem.cs:30 
  at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
  at UIKit.UIApplication.Main (System.String[] args, IntPtr principal, IntPtr delegate) [0x00005] in /Users/builder/data/lanes/2689/962a0506/source/maccore/src/UIKit/UIApplication.cs:77 
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0001c] in /Users/builder/data/lanes/2689/962a0506/source/
2016-06-02 07:57:37.350 TestApplicationiOS[179:3167] Unhandled managed exception:
Object reference not set to an instance of an object (System.NullReferenceException)
  at TestApplication.iOS.Renderers.CustomPageRenderer.<ViewWillAppear>b__0_0 (System.Object sender, System.EventArgs args) [0x00001] in C:\TestApplication\TestApplication\TestApplication.iOS\Renderers\CustomPageRenderer.cs:25 
  at UIKit.UIBarButtonItem+Callback.Call (Foundation.NSObject sender) [0x00010] in /Users/builder/data/lanes/2689/962a0506/source/maccore/src/UIKit/UIBarButtonItem.cs:30 
  at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
  at UIKit.UIApplication.Main (System.String[] args, IntPtr principal, IntPtr delegate) [0x00005] in /Users/builder/data/lanes/2689/962a0506/source/maccore/src/UIKit/UIApplication.cs:77 
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0001c] in /Users/builder/data/lanes/2689/962a0506
maccore/src/UIKit/UIApplication.cs:60 
  at TestApplication.iOS.Application.Main (System.String[] args) [0x00001] in C:\TestApplication\TestApplication\TestApplication.iOS\Main.cs:17 
/source/maccore/src/UIKit/UIApplication.cs:60 
  at TestApplication.iOS.Application.Main (System.String[] args) [0x00001] in C:\TestApplication\TestApplication\TestApplication.iOS\Main.cs:17 
2016-06-02 07:57:37.353 TestApplicationiOS[179:3167] critical: Stacktrace:
2016-06-02 07:57:37.354 TestApplicationiOS[179:3167] critical: 
Native stacktrace:
2016-06-02 07:57:37.570 TestApplicationiOS[179:3167] critical: 	0   TestApplicationiOS                  0x0000000100e01f80 mono_handle_native_sigsegv + 260
2016-06-02 07:57:37.570 TestApplicationiOS[179:3167] critical: 	1   libsystem_platform.dylib            0x0000000195b4495c _sigtramp + 68
2016-06-02 07:57:37.571 TestApplicationiOS[179:3167] critical: 	2   libsystem_pthread.dylib             0x0000000195b4d170 pthread_kill + 112
2016-06-02 07:57:37.571 TestApplicationiOS[179:3167] critical: 	3   libsystem_c.dylib                   0x0000000195a26b18 abort + 112
2016-06-02 07:57:37.571 TestApplicationiOS[179:3167] critical: 	4   TestApplicationiOS                  0x0000000100ecda28 _ZL15print_exceptionP10MonoObjectbP15NSMutableString + 0
2016-06-02 07:57:37.571 TestApplicationiOS[179:3167] critical: 	5   TestApplicationiOS                  0x0000000100e0264c mono_invoke_unhandled_exception_hook + 96
2016-06-02 07:57:37.572 TestApplicationiOS[179:3167] critical: 	6   TestApplicationiOS                  0x0000000100e01d94 mono_handle_exception_internal + 4228
2016-06-02 07:57:37.572 TestApplicationiOS[179:3167] critical: 	7   TestApplicationiOS                 
 0x0000000100e00d04 mono_handle_exception + 40
2016-06-02 07:57:37.572 TestApplicationiOS[179:3167] critical: 	8   TestApplicationiOS                  0x0000000100dfb09c handle_signal_exception + 64
2016-06-02 07:57:37.572 TestApplicationiOS[179:3167] critical: 	9   TestApplicationiOS                  0x00000001000f4840 TestApplication_iOS_Renderers_CustomPageRenderer__ViewWillAppearb__0_0_object_System_EventArgs + 128
2016-06-02 07:57:37.572 TestApplicationiOS[179:3167] critical: 	10  TestApplicationiOS                  0x0000000100b3a860 UIKit_UIBarButtonItem_Callback_Call_Foundation_NSObject + 80
2016-06-02 07:57:37.573 TestApplicationiOS[179:3167] critical: 	11  TestApplicationiOS                  0x0000000100330014 wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr + 244
2016-06-02 07:57:37.573 TestApplicationiOS[179:3167] critical: 	12  TestApplicationiOS                  0x0000000100e0c1c0 mono_jit_runtime_invoke + 1280
2016-06-02 07:57:37.573 TestApplicationiOS[179:3167] 
critical: 	13  TestApplicationiOS                  0x0000000100e603c4 mono_runtime_invoke + 124
2016-06-02 07:57:37.573 TestApplicationiOS[179:3167] critical: 	14  TestApplicationiOS                  0x0000000100dbe9cc _ZL30native_to_managed_trampoline_1P11objc_objectP13objc_selectorPP11_MonoMethodS0_PKcS7_S7_ + 404
2016-06-02 07:57:37.573 TestApplicationiOS[179:3167] critical: 	15  TestApplicationiOS                  0x0000000100dcdff4 -[UIKit_UIBarButtonItem_Callback InvokeAction:] + 80
2016-06-02 07:57:37.574 TestApplicationiOS[179:3167] critical: 	16  UIKit                               0x0000000188569404 <redacted> + 96
2016-06-02 07:57:37.574 TestApplicationiOS[179:3167] critical: 	17  UIKit                               0x0000000188569404 <redacted> + 96
2016-06-02 07:57:37.574 TestApplicationiOS[179:3167] critical: 	18  UIKit                               0x00000001885524e0 <redacted> + 612
2016-06-02 07:57:37.574 TestApplicationiOS[179:3167] critical: 	19  UIKit                               0x000000
0188568da0 <redacted> + 592
2016-06-02 07:57:37.574 TestApplicationiOS[179:3167] critical: 	20  UIKit                               0x0000000188568a2c <redacted> + 700
2016-06-02 07:57:37.575 TestApplicationiOS[179:3167] critical: 	21  UIKit                               0x0000000188561f68 <redacted> + 684
2016-06-02 07:57:37.575 TestApplicationiOS[179:3167] critical: 	22  UIKit                               0x000000018853518c <redacted> + 264
2016-06-02 07:57:37.575 TestApplicationiOS[179:3167] critical: 	23  UIKit                               0x00000001887d6324 <redacted> + 15424
2016-06-02 07:57:37.575 TestApplicationiOS[179:3167] critical: 	24  UIKit                               0x00000001885336a0 <redacted> + 1716
2016-06-02 07:57:37.575 TestApplicationiOS[179:3167] critical: 	25  CoreFoundation                      0x0000000183aac240 <redacted> + 24
2016-06-02 07:57:37.575 TestApplicationiOS[179:3167] critical: 	26  CoreFoundation                      0x0000000183aab4e4 <redacted> + 264
2016-06-02 07:
57:37.576 TestApplicationiOS[179:3167] critical: 	27  CoreFoundation                      0x0000000183aa9594 <redacted> + 712
2016-06-02 07:57:37.576 TestApplicationiOS[179:3167] critical: 	28  CoreFoundation                      0x00000001839d52d4 CFRunLoopRunSpecific + 396
2016-06-02 07:57:37.576 TestApplicationiOS[179:3167] critical: 	29  GraphicsServices                    0x000000018d1eb6fc GSEventRunModal + 168
2016-06-02 07:57:37.576 TestApplicationiOS[179:3167] critical: 	30  UIKit                               0x000000018859afac UIApplicationMain + 1488
2016-06-02 07:57:37.576 TestApplicationiOS[179:3167] critical: 	31  TestApplicationiOS                  0x0000000100ba9984 wrapper_managed_to_native_UIKit_UIApplication_UIApplicationMain_int_string___intptr_intptr + 324
2016-06-02 07:57:37.577 TestApplicationiOS[179:3167] critical: 	32  TestApplicationiOS                  0x0000000100b388fc UIKit_UIApplication_Main_string___intptr_intptr + 44
2016-06-02 07:57:37.577 TestApplicationiOS[179:3167] critic
al: 	33  TestApplicationiOS                  0x0000000100b388bc UIKit_UIApplication_Main_string___string_string + 172
2016-06-02 07:57:37.577 TestApplicationiOS[179:3167] critical: 	34  TestApplicationiOS                  0x00000001000f4090 TestApplication_iOS_Application_Main_string__ + 128
2016-06-02 07:57:37.577 TestApplicationiOS[179:3167] critical: 	35  TestApplicationiOS                  0x0000000100330014 wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr + 244
2016-06-02 07:57:37.577 TestApplicationiOS[179:3167] critical: 	36  TestApplicationiOS                  0x0000000100e0c1c0 mono_jit_runtime_invoke + 1280
2016-06-02 07:57:37.578 TestApplicationiOS[179:3167] critical: 	37  TestApplicationiOS                  0x0000000100e603c4 mono_runtime_invoke + 124
2016-06-02 07:57:37.578 TestApplicationiOS[179:3167] critical: 	38  TestApplicationiOS                  0x0000000100e645ac mono_runtime_exec_main + 400
2016-06-02 07:57:37.578 TestApplicationiOS[179:3167] critical: 	39
  TestApplicationiOS                  0x0000000100ee2fe4 xamarin_main + 1840
2016-06-02 07:57:37.578 TestApplicationiOS[179:3167] critical: 	40  TestApplicationiOS                  0x0000000100dd42e0 main + 96
2016-06-02 07:57:37.578 TestApplicationiOS[179:3167] critical: 	41  libdyld.dylib                       0x0000000195996a08 <redacted> + 4
2016-06-02 07:57:37.578 TestApplicationiOS[179:3167] critical: 
=================================================================
Got a SIGABRT while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================
The app has been terminated.
Comment 6 Phillip 2016-06-01 22:24:54 UTC
Created attachment 16162 [details]
Repro project from comment 5.
Comment 7 Trevor 2016-09-04 22:43:08 UTC
+1 

We are using Xamarin Forms and although we have not been able to reproduce this issue, our users have experiencing this crash on various iOS devices/versions with our apps that are built with XForms including version 2.3.1.114. 

We are using Xamarin Insights. Could this be related to the issue that Insights prevents mono from handling SIGSEGV? https://bugzilla.xamarin.com/show_bug.cgi?id=4120
Comment 8 Mark Erickson 2016-09-07 11:50:48 UTC
I am seeing this issue intermittently also. I just recently updated to XForms 2.3.1.114.  Has anyone found a solution to this or at least why it is happening?
Comment 9 Cooper Hilscher 2017-03-03 17:31:08 UTC
We are seeing this very often on a particular app. I cant reproduce it every time, but it happens mostly when popping back to a page which is in a master detail. 

Using forms version 2.3.3.193.

Any possible workarounds available / is this on anyones radar to fix?
Comment 10 Daniel Maclean 2017-04-04 10:15:34 UTC
Just confirming that we have observed this as well in a few of our apps. We cannot reproduce and it doesn't appear to have a pattern associated with the crash. Our apps are using Xamarin Forms 2.3.3.193:

Exception Type:  SIGABRT
Exception Codes: #0 at 0x192a17014
Crashed Thread:  0

Application Specific Information:
*** Terminating app due to uncaught exception 'System.NullReferenceException', reason: 'System.NullReferenceException: Object reference not set to an instance of an object'

Xamarin Exception Stack:
  at Xamarin.Forms.Platform.iOS.NavigationRenderer.GetAppearedOrDisappearedTask (Xamarin.Forms.Page page) [0x00018] in <a6cd19dbb15f4cf7a888f95a192e4376>:0 
  at Xamarin.Forms.Platform.iOS.NavigationRenderer.RemoveViewControllers (System.Boolean animated) [0x00055] in <a6cd19dbb15f4cf7a888f95a192e4376>:0 
  at Xamarin.Forms.Platform.iOS.NavigationRenderer.PopViewController (System.Boolean animated) [0x00000] in <a6cd19dbb15f4cf7a888f95a192e4376>:0 
  at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
  at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Users/builder/data/lanes/3985/35d1ccd0/source/xamarin-macios/src/UIKit/UIApplication.cs:79 
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Users/builder/data/lanes/3985/35d1ccd0/source/xamarin-macios/src/UIKit/UIApplication.cs:63 
  at <appname>.iOS.Application.Main (System.String[] args) [0x00000] in <5d5f81b4fcfe455aa11a32bc27071a78>:0
Comment 11 Samantha Houts 2017-04-17 18:23:22 UTC
Returning to NEW status.
Comment 12 Jimmy [MSFT] 2017-04-17 22:07:49 UTC
Created attachment 21583 [details]
repro project

I was able to reproduce the issue with the attached project so I am confirming this report. 

I am re-attaching the same project but with Forms updated to 2.3.4.231. I ran the project on an iPhone 7 iOS 10.3 simulator.

Crash stack trace: https://gist.github.com/jimmgarrido/f1d7f126aac868eff64dfa60e8d41458


### Steps to Reproduce
1. Run the attached project on iOS
2. Press "Navigate to page ...." until you reach page 4
3. Press the pencil icon in the top repeatedly to go back to the first page
4. Repeat step 2 and 3


### Expected Result
The app will navigate back to the first page


### Actual Results
The app will crash with an NRE before reaching the first page. The crash does not occur _every_ time, but I was seeing it after repeating the steps above 2 or 3 times. 


### Version Tests
2.3.5-pre1  BAD
2.3.4.231   BAD
2.3.3.193   BAD
Comment 13 RSH 2017-04-28 19:46:52 UTC
This is definitely a race condition on our app.  We have SQLight doing some saving on the override OnDisappearing from screen 6, then if you click back quickly to get back to screen 4, it will crash with this issue.  The only way I have been able to fix this is:

        protected override async void OnAppearing()
        {
            base.OnAppearing();

            if (Device.RuntimePlatform == Device.iOS)
            {
                if (Navigation.NavigationStack.Count == 6)
                {
                    await UserDialogs.Instance.AlertAsync("Guest Information Saved");
                }
            }
            _guestListView.ItemsSource = App.DataSource.CurrentAttendee.guests;
        }

Which when trying to trigger the crash, instead of crashing, the output console says:

2017-04-28 12:44:33.905 iotaCheckiniOS[26931:302554] popToViewController:transition: called on <Xamarin_Forms_Platform_iOS_NavigationRenderer 0x7fb8203f2000> while an existing transition or presentation is occurring; the navigation stack will not be updated.
Comment 14 Sanya Andreichuk 2017-05-02 12:33:58 UTC
 
Anybody knows how to workaroud the issue ?
Comment 15 Sanya Andreichuk 2017-05-02 14:40:15 UTC
Seems it only happens when you mix use of default navigation back button and custom back button with PopAsync method. I've removed the default back button 

NavigationPage.SetHasBackButton(this, false);


and leave only my custom back button and it fixed the issue.
Comment 16 Hines Vaughan III 2017-05-09 20:44:51 UTC
Just to chime in here, we are not using a custom back button and we are still getting this exception.
Comment 17 Emman Vazz 2017-05-09 21:33:10 UTC
Same no custom back button.
Comment 18 Justin 2017-05-09 22:07:22 UTC
I also have this issue and no custom back button.
Comment 19 David Dunscombe 2017-05-15 08:03:46 UTC
If your really desperate you can rebuild the ios xamarin forms library and modify GetAppearedOrDisappearedTask and add this check to the top (this is from 2.3.2.127)

> Task<bool> GetAppearedOrDisappearedTask(Page page)
> 		{
> 			var tcs = new TaskCompletionSource<bool>();
> 
> 			var renderer = Platform.GetRenderer(page);
> 			if (renderer == null || renderer.ViewController == null)
> 				return Task.FromResult(true);
> 
> 			var parentViewController = renderer.ViewController.ParentViewController as ParentingViewController;
> 			if (parentViewController == null)
> 				throw new NotSupportedException("ParentingViewController parent could not be found. Please file a bug.");

I did this and it worked for me - not seen the crash since, although it seems a little bit hacky as I don't know the cause of the problem.
Comment 21 Jason Smith [MSFT] 2017-05-24 17:32:19 UTC
This should be fixed in 2.3.6-pre1
Comment 22 faceoffers28 2017-06-21 02:49:17 UTC
Same problem with 2.3.4.231. I just tried to Install-Package Xamarin.Forms -Version 2.3.6-pre1 -Pre and it's not available. Will it be released soon? Thanks!
Comment 23 faceoffers28 2017-06-28 14:42:45 UTC
Hello everyone, I'm not sure if this is fixed as I haven't been able to install 2.3.6-pre1, but I haven't seen the issue since I started removing pages from the stack. My issue had something to do with a BusyPage (ContentPage) that I was pushing onto the Stack before calling the actual Page I wanted to display. This is the only good way I could find to show a seamless transition from one page to the next. Anyway, in one area of the app, I would go from HomePage to SearchPage (push BusyPage) to RedeemPage (push BusyPage) to ReceiptPage. When I would go Back, the screen would sometimes turn all white (except the navigation menu across the top) and crash. This wouldn't happen all the time and it would happen on either the SearchPage or the HomePage. I placed this bit of code in the OnAppearing method of the Page that is pushed after the BusyPage and I haven't seen the problem since. Basically, I'm removing the BusyPage from the Stack.

 var busyPage = Navigation.NavigationStack.FirstOrDefault(p => p is BusyPage);
            if (busyPage != null)
            {
                Navigation.RemovePage(busyPage);
            }
Comment 24 Daniel Maclean 2017-09-08 09:33:10 UTC
Following the trail on GitHub, the fix should be available in 2.4.0:

https://github.com/xamarin/Xamarin.Forms/commit/8f7b1f7f17f462caa05b84a96ea23ba622c1b771.

You should be able to find that here @ 2.4.0-pre2:

https://www.nuget.org/packages/Xamarin.Forms/2.4.0.269-pre2

We will be testing this soon and will feedback when done.
Comment 25 Alex 2017-09-18 08:27:00 UTC
Is this classed as a fix? For me all it does is stop the crashing part. It does not load the page correctly. I have a Tabbed Page that does not appear at all with this "Fix", you click back and see it for a second and then it disappears.
Comment 26 Alex 2017-09-18 11:40:19 UTC
Is this now because of the Tabbed page? I cannot find a fix for this and it is so annoying! This may fix a single page but the tabbed pages seem to find the stack is empty and the renderer changes? No idea whats going on with this.
Comment 27 Sanya Andreichuk 2017-09-20 17:24:46 UTC
Seems v2.4 not fixed the cause of the problem, but only prevent from NullReferenceException.  Blank page still appears, but now it is not crashing  after clicking back button.
Comment 28 Sanya Andreichuk 2017-09-21 17:33:31 UTC
I hope it would be helpful

http://sandreichuk.blogspot.com/2017/09/xamarinios-xamarinforms-back-navigation.html
Comment 29 Matronix 2017-10-05 01:20:06 UTC
Using version 2.3.4.270 and still having this same issue.

Note You need to log in before you can comment on or make changes to this bug.