Bug 24887 - Adding an already initialised ContentPage to a 2nd NavigationPage
Summary: Adding an already initialised ContentPage to a 2nd NavigationPage
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 1.3.0
Hardware: Macintosh Other
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2014-11-27 08:28 UTC by Tim Brand
Modified: 2014-12-15 12:22 UTC (History)
5 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Tim Brand 2014-11-27 08:28:27 UTC
Adding an existing ContentPage reference (which has been created before) to another new NavigationPage will result in an exception.

I created my ContentPage once and want to use it on different locations, so I was required to add it again in another NavigationPage instance, which isn't possible.

Platform tested: iOS

Code to reproduce:
var p = new ContentPage ();
var navP1 = new NavigationPage (p);
var navP2 = new NavigationPage (p);

On line 3 the following exception occurs:

2014-11-27 14:26:24.069 XamarinFormsTestsiOS[19577:6414377] Unhandled managed exception: Object reference not set to an instance of an object (System.NullReferenceException)
  at Xamarin.Forms.NavigationProxy.set_Inner (INavigation value) [0x00000] in <filename unknown>:0 
  at Xamarin.Forms.VisualElement.OnParentSet () [0x00000] in <filename unknown>:0 
  at Xamarin.Forms.Page.OnParentSet () [0x00000] in <filename unknown>:0 
  at Xamarin.Forms.Element.set_Parent (Xamarin.Forms.Element value) [0x00000] in <filename unknown>:0 
  at Xamarin.Forms.Element.OnChildAdded (Xamarin.Forms.Element child) [0x00000] in <filename unknown>:0 
  at Xamarin.Forms.Page.OnInternalAdded (Xamarin.Forms.VisualElement view) [0x00000] in <filename unknown>:0 
  at Xamarin.Forms.Page.InternalChildrenOnCollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00000] in <filename unknown>:0 
  at System.Collections.ObjectModel.ObservableCollection`1[Xamarin.Forms.Element].OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00014] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/ 
  at System.Collections.ObjectModel.ObservableCollection`1[Xamarin.Forms.Element].InsertItem (Int32 index, Xamarin.Forms.Element item) [0x0000e] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/ 
  at System.Collections.ObjectModel.Collection`1[Xamarin.Forms.Element].Add (Xamarin.Forms.Element item) [0x0000c] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Collections.ObjectModel/Collection.cs:81 
  at Xamarin.Forms.NavigationPage.PushPage (Xamarin.Forms.Page page) [0x00000] in <filename unknown>:0 
  at Xamarin.Forms.NavigationPage..ctor (Xamarin.Forms.Page root) [0x00000] in <filename unknown>:0 
  at XamarinFormsTests.App..ctor () [0x00020] in /Users/tim/Projects/XamarinFormsTests/XamarinFormsTests/App.cs:20 
  at XamarinFormsTests.iOS.AppDelegate.FinishedLaunching (MonoTouch.UIKit.UIApplication uiApplication, MonoTouch.Foundation.NSDictionary launchOptions) [0x00007] in /Users/tim/Projects/XamarinFormsTests/iOS/AppDelegate.cs:16 
  at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
  at MonoTouch.UIKit.UIApplication.Main (System.String[] args, IntPtr principal, IntPtr delegate) [0x00005] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:62 
  at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:46 
  at XamarinFormsTests.iOS.Application.Main (System.String[] args) [0x00008] in /Users/tim/Projects/XamarinFormsTests/iOS/Main.cs:17
Comment 1 Parmendra Kumar 2014-12-08 08:05:57 UTC
I have checked this issue and I am able to reproduce this issue. To reproduce this issue I have followed steps mentioned in the bug description.

Screencast: http://www.screencast.com/t/hf9jM4WAc
Application Output: https://gist.github.com/Parmendrak/511c47327f9290852f3c
IDE Log: https://gist.github.com/Parmendrak/1078f43a36548e35b79e
Build Output: https://gist.github.com/Parmendrak/80d1677c65a1c88c5e59

Environment info:

Xamarin Studio 5.5.4 (build 15)
Mono 3.10.0 ((detached/92c4884)
Xamarin.Android : (Business Edition)
Xcode 6.1 (6602)
Xamarin.iOS : (Business Edition)
Xamarin.Mac : (Business Edition)
Operating System: Mac OS X 10.9.4
Comment 2 Jason Smith [MSFT] 2014-12-15 12:22:07 UTC
Already talked about on forum