Xamarin.Forms.NavigationPage.GetHasNavigationBar, NullReferenceException !!

My App runs just fine on Android But whenever I run it on iOS Device it will crash with the following error:
"Object reference not set to an instance of an object"
Source: "Xamarin.Forms.Core".

I have a MasterDetial application and I need to open a specific page when the app switch to landscape mode so what happened is:
I call each Detail page using NavigationPage except the page that I need to run it in the landscape mode I call it without. On Android this works just fine

the following code is used to detect a change in the screen resolution. At the end I'm sitting the IdPage as the main page then the App crashes.

public partial class MasterDetail : MasterDetailPage
protected override async void OnSizeAllocated(double width, double height)
base.OnSizeAllocated(width, height);
if (Math.Abs(width - this.width) < double.Epsilon || Math.Abs(height - this.height) < double.Epsilon) return;
this.width = width;
this.height = height;
if (!(width >= height) || App.MasterDetail.Detail == App.LoginPage) return;

        if (IsPresented)
            IsPresented = false;
            await Task.Delay(100);
        if (CustomerAccount == null) return;
        **Application.Current.MainPage = App.ibringIDPage;**



at Xamarin.Forms.NavigationPage.GetHasNavigationBar (Xamarin.Forms.BindableObject page) [0x00000] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\NavigationPage.cs:102
at Xamarin.Forms.Platform.iOS.NavigationRenderer.ViewDidLayoutSubviews () [0x0001f] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.iOS\Renderers\NavigationRenderer.cs:157
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/5481/2f8bbec0/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/5481/2f8bbec0/source/xamarin-macios/src/UIKit/UIApplication.cs:63
at CustomerApp.iOS.Application.Main (System.String[] args) [0x00001]

Please any help to solve or explain why it behave like this.
thanks in advance.

Sign In or Register to comment.