Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
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
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.
Created attachment 22673 [details]
Screenshot showing error
A System.InvalidCast Exception is thrown for Android when using a custom Navigation Renderer and when calling the 'base.OnPushAsync(view, false)' method.
REPLICATION CODE on GITHUB
To replicate, please run the following code from Github: https://github.com/bbl-Laobu/CustomBackIcon.git
The following classes are used to demonstrate the bug:
public class CustomNavigationPage : NavigationPage
public CustomNavigationPage(Page startupPage) : base(startupPage)
public partial class App : Application
MainPage = new CustomNavigationPage(new StartPage());
[assembly: ExportRenderer(typeof(CustomNavigationPage), typeof(ChangeBackIcon.Droid.NavigationPageRendererDroid))]
public class NavigationPageRendererDroid : NavigationRenderer
public NavigationPageRendererDroid() : base()
protected override Task<bool> OnPopViewAsync(Page page, bool animated)
System.Diagnostics.Debug.WriteLine(">>> DEBUG Droid: OnPopViewAsync");
return base.OnPopViewAsync(page, false);
protected override Task<bool> OnPushAsync(Page view, bool animated)
System.Diagnostics.Debug.WriteLine(">>> DEBUG Droid: OnPushAsync");
return base.OnPushAsync(view, false);
The cause of your crash appears to be due to the fact that the app is running under AppCompat via FormsAppCompatActivity. There are two renderers for NavigationPage; NavigationRenderer, which your example uses, and NavigationPageRenderer, which is what is used by AppCompat. Adjusting your renderer to inherit from NavigationPageRenderer instead should resolve the crash. Similarly, changing the app to inherit from FormsApplicationActivity while leaving the example's renderer as is would let the app run as expected.
Yes indeed, the System.InvalidCast Exception gets indeed resolved this way.