Xamarin.Forms
Xamarin.Forms copied to clipboard
Xamarin Forms Shell back navigation fails with null reference in iOS
This issue has been moved from a ticket on Developer Community.
I have Xamarin Forms app that is navigating from a flyout menu item to a ContentPage using a registered route. The navigating FROM page is a Visual Material page and so is the navigated To page, with the To page using Shell.PresentationMode=Animated.
Once the user has made changes on this page, they press a button to save their choices and I programmatically navigate back using:
await Shell.Current.GoToAsync("..");
This works fine in Android, but fails with the following error in iOS:
2020-08-28 13:36:21.276385-0400 Connect.iOS[48651:4311125] [AppCenterCrashes] ERROR: +[MSWrapperLogger MSWrapperLog:tag:level:]/10 Unhandled Exception:
System.NullReferenceException: Object reference not set to an instance of an object
at Xamarin.Forms.Material.iOS.MaterialButtonRenderer.ApplyThemeIfNeeded () [0x00000] in D:\a\1\s\Xamarin.Forms.Material.iOS\MaterialButtonRenderer.cs:118
at Xamarin.Forms.Material.iOS.MaterialButtonRenderer.LayoutSubviews () [0x00006] in D:\a\1\s\Xamarin.Forms.Material.iOS\MaterialButtonRenderer.cs:88
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 /Library/Frameworks/Xamarin.iOS.framework/Versions/13.20.2.2/src/Xamarin.iOS/UIKit/UIApplication.cs:86
at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0000e] in /Library/Frameworks/Xamarin.
iOS.framework/Versions/13.20.2.2/src/Xamarin.iOS/UIKit/UIApplication.cs:65
at Connect.iOS.Application.Main (System.String[] args) [0x00001] in C:\Source\CommonPath\ENC\UI\CPConnect\Connect.iOS\Main.cs:12
If I comment out that navigation code, and leave the back navigation to the user, clicking on the back button works fine on both platforms.
Using Xamarin.Forms and Xamarin.Forms.Visual.Material v4.8.0.1269
Original Comments
Feedback Bot on 8/31/2020, 01:49 AM:
We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.
Enbi Zhang Zhang [MSFT] on 9/2/2020, 00:16 AM:
Thanks for your feedback.
Could you provide a simple project to let us reproduce your issue?
Why do we ask for more info?
We try to reproduce all issues reported with the information provided in the description and comments. When we can’t reproduce the issue, we ask you for more information so we can resolve the issue as quickly and efficiently as possible.
In our guidelines, you can get tips on how to provide clear and simple reproducible steps.
Feedback Bot on 9/2/2020, 06:41 PM:
We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.
Original Solutions
(no solutions)
I encountered the same problem, is there a solution now
Same problem on my end with Xamarin.Forms -Version 5.0.0.1874. A small delay of 50 ms (await Task.Delay()) solved it in the simulator. However I'm not sure if this works on each device.
I'm calling Shell.Current.GoToAsync
while the latest page in the NavigationStack is "OnDisappearing". Guess this is the problem.
@konglu2016 @AndreasReitberger this should be fixed with the next release of 5.0
You can test the nightlies here if you'd like https://github.com/xamarin/Xamarin.Forms/wiki/Nightly-Builds
If you're still having the issue please attach a repro
@PureWeen Just tried the latest release, and this still happens. Got this error when navigating with Shell.GoToAsync() to another page in code, while the current one is disappearing.
at Xamarin.Forms.Shell.GetNavBarIsVisible (Xamarin.Forms.BindableObject obj) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Shell\Shell.cs:104
at Xamarin.Forms.Platform.iOS.ShellSectionRenderer+NavDelegate.WillShowViewController (UIKit.UINavigationController navigationController, UIKit.UIViewController viewController, System.Boolean animated) [0x00028] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\ShellSectionRenderer.cs:628
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 /Library/Frameworks/Xamarin.iOS.framework/Versions/14.8.0.3/src/Xamarin.iOS/UIKit/UIApplication.cs:86
at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0000e] in /Library/Frameworks/Xamarin.iOS.framework/Versions/14.8.0.3/src/Xamarin.iOS/UIKit/UIApplication.cs:65
at RemoteControlRepetierServer.iOS.Application.Main (System.String[] args) [0x00001] in C:\RCRepetierPro\Source\RemoteControlRepetierServer\RCRepetierServer\RemoteControlRepetierServer.iOS\Main.cs:17
I'm calling the Shell.GoToAsync() on the main thread. Could this be the problem?
public static async Task<bool> GoToAsync(string Target, bool FlyoutIsPresented = false, int Delay = -1)
{
try
{
Shell.Current.FlyoutIsPresented = FlyoutIsPresented;
if (Delay != -1)
await Task.Delay(Delay);
MainThread.BeginInvokeOnMainThread(async () =>
{
var lastPart = getCurrentRoute();
if (lastPart != Target)
await Shell.Current.GoToAsync(Target);
else
{
System.Diagnostics.Debug.WriteLine(string.Format("ShellNavigationManager: Tried to open the same route again", Target));
}
});
return true;
}
catch (Exception exc)
{
// Log error
EventManager.LogError(exc);
return false;
}
}
Im having this same issue after updating to Forms 5(stable channel). I am supposed to release my app this week. WTF.
System.NullReferenceException: Object reference not set to an instance of an object at Xamarin.Forms.Shell.GetNavBarIsVisible (Xamarin.Forms.BindableObject obj) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Shell\Shell.cs:104 at Xamarin.Forms.Platform.iOS.ShellSectionRenderer+NavDelegate.WillShowViewController (UIKit.UINavigationController navigationController, UIKit.UIViewController viewController, System.Boolean animated) [0x00028] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\ShellSectionRenderer.cs:628 at 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 /Library/Frameworks/Xamarin.iOS.framework/Versions/14.8.0.3/src/Xamarin.iOS/UIKit/UIApplication.cs:86 at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0000e] in /Library/Frameworks/Xamarin.iOS.framework/Versions/14.8.0.3/src/Xamarin.iOS/UIKit/UIApplication.cs:65 at Attendance.iOS.Application.Main (System.String[] args) [0x00001] in /Users/shahid/Github/AttendanceApp/Attendance.iOS/Main.cs:12
@AndreasReitberger @shahid-aman your exceptions seem related to each other but not related to this issue
If you could create a new issue with a repro that would be helpful
@AndreasReitberger @shahid-aman your exceptions seem related to each other but not related to this issue
If you could create a new issue with a repro that would be helpful
Done 👍🏻
The problem repeats itself, OnAppearing is called, Then it throws an exception. Xamarin.Forms version 5.0.0.2012 iPhone XR, iOS version 14.6. VisualStudio version 16.10.2
The problem repeats itself, OnAppearing is called, Then it throws an exception. Xamarin.Forms version 5.0.0.2012 iPhone XR, iOS version 14.6. VisualStudio version 16.10.2
Yes, issue is still not fixed... and no life sign since more than 20 days from Xamarin👎🏻
Is there any updates for this issue?
Buller!?