1

I am writing a custom renderer for master detail page. And I get a invalid cast exception in the main activity.

 public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity
    {
        protected override void OnCreate(Bundle bundle)
        {
            //TabLayoutResource = Resource.Layout.Tabbar;
            //ToolbarResource = Resource.Layout.Toolbar;

            base.OnCreate(bundle);

            global::Xamarin.Forms.Forms.Init(this, bundle);
            LoadApplication(new App());
        }
    }


[assembly: ExportRenderer(typeof(Xamarin.Forms.MasterDetailPage), typeof(CustomRenderer))]
namespace App3.Droid.Renderer
{
    public class CustomRenderer : MasterDetailPageRenderer
    {

        public CustomRenderer(Context context) : base(context)
        {
        }
    }
}
Robbit
  • 4,300
  • 1
  • 13
  • 29
  • can you reformat you code so that the markdown is unbroken – rgalbo Apr 11 '18 at 23:28
  • Unhandled Exception: System.InvalidCastException: Specified cast is not valid. 04-12 09:56:23.588 D/Mono (11599): DllImport attempting to load: '/system/lib64/liblog.so'. 04-12 09:56:23.589 D/Mono (11599): DllImport loaded library '/system/lib64/liblog.so'. 04-12 09:56:23.589 D/Mono (11599): DllImport searching in: '/system/lib64/liblog.so' ('/system/lib64/liblog.so'). – Nandini Nadig Apr 12 '18 at 16:59
  • I cannot paste the whole error as it exceeds the length – Nandini Nadig Apr 12 '18 at 17:04
  • 04-12 09:56:23.661 I/MonoDroid(11599): System.InvalidCastException: Specified cast is not valid. 04-12 09:56:23.661 I/MonoDroid(11599): at Xamarin.Forms.Platform.Android.AppCompat.MasterDetailContainer.get_FragmentManager () [0x00000] in D:\agent\_work\1\s\Xamarin.Forms.Platform.Android\AppCompat\MasterDetailContainer.cs:27 04-12 09:56:23.661 I/MonoDroid(11599): at Xamarin.Forms.Platform.Android.AppCompat.MasterDetailContainer.AddChildView (Xamarin.Forms.VisualElement childView) [0x0007c] in D:\agent\_work\1\s\Xamarin.Forms.Platform.Android\AppCompat\MasterDetailContainer.cs:98 – Nandini Nadig Apr 12 '18 at 17:04
  • I checked your code and you have inherited from public class MainActivity:global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity and I am from FormsApplicationActivity. – Nandini Nadig Apr 12 '18 at 17:30
  • Sorry for late, please "@" me, so I can see your comment immediately. Look [here](https://stackoverflow.com/questions/33318416/migrating-to-formsapplicationactivity-causing-exceptions-in-navigationrenderer), check your render's namespace, make sure its not `AppCompat`. – Robbit Apr 16 '18 at 01:34
  • yes .. But no luck – Nandini Nadig Apr 16 '18 at 15:45

1 Answers1

0

I have made a simple demo for MasterDetailPage on github, you can refer to it to custom your MasterDetailPage.

Robbit
  • 4,300
  • 1
  • 13
  • 29