Bug 26898 - NullReferenceException Xamarin.Forms.NavigationPage.GetHasNavigationBar
Summary: NullReferenceException Xamarin.Forms.NavigationPage.GetHasNavigationBar
Status: RESOLVED NORESPONSE
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 1.3.3
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: ---
Assignee: Rui Marinho
URL:
Depends on:
Blocks:
 
Reported: 2015-02-10 02:14 UTC by Stuart Campbell
Modified: 2016-04-08 19:23 UTC (History)
7 users (show)

Tags:
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:
Status:
RESOLVED NORESPONSE

Description Stuart Campbell 2015-02-10 02:14:50 UTC
A few hours ago I updated to 1.3.3.632. Within approximately 4 hours of active debugging on my iPhone6 I received a NullReferenceException in Xamarin.Forms.Core. I have only received this once, reboot of the App with no code changes works - appears to be a transient issue. 

  at Xamarin.Forms.NavigationPage.GetHasNavigationBar (Xamarin.Forms.BindableObject page) [0x00000] in <filename unknown>:0 
  at Xamarin.Forms.Platform.iOS.NavigationRenderer.ViewDidLayoutSubviews () [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 /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:62 
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0001c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:45 
  at *removed*
Comment 1 Stuart Campbell 2015-02-10 02:17:33 UTC
Apologies, the above should read "updated to 1.3.3.6323".
Comment 2 Ram Chandra 2015-02-13 01:11:49 UTC
I have checked this issue with Xamarin.Forms:1.3.4.6329-pre3 / 1.3.36323 but I am unable to reproduce the reported behavior.

Steps I followed:

1. Create Blank App (Xamarin.Forms Portable ) forms application.
2. Write the following code in App class App() ctor
    MainPage = new NavigationPage (new Page1()) {Title="Navigation Stack"} ;
3. Write the following code in App class

public class Page1 : ContentPage
    {
        public Page1 ()
        {   var ti = new ToolbarItem ();
            ti.Text = "a";
            ToolbarItems.Add (ti);

           var test= NavigationPage.GetHasNavigationBar(this);
 
            var b = new Button { Text = "Next" };
            b.Clicked += async (sender, e) => {
                await Navigation.PushAsync (new Page2());
            } ;
            Title = "Page 1";
            Content = new StackLayout { 
                BackgroundColor = Color.Red,
                Children = {
                    new Label { Text = "Page 1", FontSize=Device.GetNamedSize(NamedSize.Large, typeof(Label)) }
                    , b
                }
            } ;
        }
    }

    public class Page2 : ContentPage
    {
        public Page2 ()
        {   
            var test= NavigationPage.GetHasNavigationBar(this);
            var b = new Label() { 
                Text = "This is page2"
            
            };
            Title = "Page 2";
            Content = new StackLayout { 
                BackgroundColor = Color.Aqua,
                Children = {
                    new Label { Text = "Page 2", FontSize=Device.GetNamedSize(NamedSize.Large, typeof(Label)) }
                    , b
                }
            } ;
        }
    }

3. Build and debug the project.
4. set the breakpoint on code and debug the application.

Observation: I am able to debug the application. I am not getting any error or exception.

> appears to be a transient issue.
This is an intermittent behavior

If you will get this issue again. Could you please attached sample project, build info and logs( application output and IDE logs). 

You can get these info from here:

1 For Build info: 
  Xamarin Studio => About Xamarin Studio => Show Details => Copy Info

2. For IDE logs:
   Xamarin Studio => Help => Open log directory => Ide logs( with latest timestamp)

Please also mentioned the Xamarin.Forms version you are using.
Comment 3 Cody Beyer (MSFT) 2015-06-06 11:42:30 UTC
Able to reproduce with the above sample, as well as private sample
Comment 4 Rui Marinho 2015-06-09 06:10:52 UTC
We are not able to reproduce this using the above code on 1.4.2 our 1.4.3-pre1 , can you provide a sample to reproduce the issue? 

Thanks
Comment 5 Jason Smith [MSFT] 2015-07-06 15:42:04 UTC
The implementation of the method is as follows:

public static bool GetHasNavigationBar(BindableObject page)
{
	return (bool)page.GetValue (HasNavigationBarProperty);
}

The only way this throws an exception with the stacktrace you have provided is either GetValue returns a non-bool result, which is well tested, or page is null, which is user provided. I believe the issue to be page being null.
Comment 6 Jason Smith [MSFT] 2015-07-06 15:43:09 UTC
This means Current is somehow being made null in the NavigationPage.
Comment 7 Rui Marinho 2015-07-10 05:25:47 UTC
Cody you confirmed with what forms version? please attach a repo to the issue.

Thanks
Comment 8 Samantha Houts [MSFT] 2016-04-08 19:23:54 UTC
Thank you for your bug report. As we have not received the information requested, we cannot properly triage your bug and are marking it resolved.

Warm regards,
Xamarin Forms Team