Bug 59878 - Using a custom renderer for NavigationPage results in InvalidCastException when calling base.OnElementChanged()
Summary: Using a custom renderer for NavigationPage results in InvalidCastException wh...
Status: CONFIRMED
Alias: None
Product: Forms
Classification: Xamarin
Component: Android (show other bugs)
Version: 2.4.0
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-10-01 06:45 UTC by Nicholas Bauer
Modified: 2017-10-03 21:25 UTC (History)
2 users (show)

Tags: custom renderer, navigationpage, ac
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 for Bug 59878 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
CONFIRMED

Description Nicholas Bauer 2017-10-01 06:45:31 UTC
Using this custom renderer causes InvalidCastException inside the base class OnElementChanged function:

using Xamarin.Forms.Platform.Android;
using Xamarin.Forms;
using MyApp.Droid.Renderers;

[assembly: ExportRenderer(typeof(NavigationPage), typeof(NavigationPageRenderer))]
namespace MyApp.Droid.Renderers
{
    public class NavigationPageRenderer : NavigationRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<NavigationPage> e)
        {
            base.OnElementChanged(e);
        }
    }
}

It may or may not matter, but in my case, the NavigationPage in question is being used inside a MasterDetailPage Detail pane.


This bug appears to be documented elsewhere:

https://forums.xamarin.com/discussion/71524/masterdetail-and-navigationpage-custom-renderer-both-fail

https://forums.xamarin.com/discussion/96232/invalidcastexception-when-calling-base-onelementchanged-e-in-custom-renderer
Comment 1 Nicholas Bauer 2017-10-03 21:25:17 UTC
Ah... I figured out the problem.

It's AppCompat vs. regular. Which I had no idea was a thing until encountering this.

It would be really useful to have an informative exception message to direct developers to the correct classes.