Bug 35194 - V7 Toolbar exception when launching app
Summary: V7 Toolbar exception when launching app
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 1.5.2
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2015-10-23 06:54 UTC by Rogier van der Hee
Modified: 2016-04-13 19:28 UTC (History)
4 users (show)

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 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.

Related Links:

Description Rogier van der Hee 2015-10-23 06:54:06 UTC
I have converted my app to AppCompat model, but when I launch my app it crashes:

10-23 12:08:17.774 I/MonoDroid(23931): System.InvalidCastException: Unable to convert instance of type 'Android.Widget.HorizontalScrollView' to type 'android/support/v7/widget/Toolbar'.
10-23 12:08:17.774 I/MonoDroid(23931): at Java.Interop.JavaObjectExtensions._JavaCast<Android.Support.V7.Widget.Toolbar> (Android.Runtime.IJavaObject) <0x00678>
10-23 12:08:17.774 I/MonoDroid(23931): at Java.Interop.JavaObjectExtensions.JavaCast<Android.Support.V7.Widget.Toolbar> (Android.Runtime.IJavaObject) <0x0005f>
10-23 12:08:17.774 I/MonoDroid(23931): at Android.Runtime.Extensions.JavaCast<Android.Support.V7.Widget.Toolbar> (Android.Runtime.IJavaObject) <0x0005f>
10-23 12:08:17.774 I/MonoDroid(23931): at Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer.SetupToolbar () <IL 0x00026, 0x0017f>
10-23 12:08:17.774 I/MonoDroid(23931): at Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer.OnElementChanged (Xamarin.Forms.Platform.Android.ElementChangedEventArgs`1<Xamarin.Forms.NavigationPage>) <IL 0x000b3, 0x005a3>
10-23 12:08:17.774 I/MonoDroid(23931): at Xamarin.Forms.Platform.Android.VisualElementRenderer`1<Xamarin.Forms.NavigationPage>.SetElement (Xamarin.Forms.NavigationPage) <0x00823>
10-23 12:08:17.774 I/MonoDroid(23931): at Xamarin.Forms.Platform.Android.VisualElementRenderer`1<Xamarin.Forms.NavigationPage>.Xamarin.Forms.Platform.Android.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement) <0x0012b>
10-23 12:08:17.774 I/MonoDroid(23931): at Xamarin.Forms.Platform.Android.RendererFactory.GetRenderer (Xamarin.Forms.VisualElement) <IL 0x00021, 0x0014f>
10-23 12:08:17.774 I/MonoDroid(23931): at Xamarin.Forms.Platform.Android.AppCompat.Platform.AddChild (Xamarin.Forms.Page,bool) <IL 0x00016, 0x000cb>
10-23 12:08:17.774 I/MonoDroid(23931): at Xamarin.Forms.Platform.Android.AppCompat.Platform.SetPage (Xamarin.Forms.Page) <IL 0x00091, 0x00543>
10-23 12:08:17.774 I/MonoDroid(23931): at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.InternalSetPage (Xamarin.Forms.Page) <IL 0x000a2, 0x00463>
10-23 12:08:17.774 I/MonoDroid(23931): at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.SetMainPage () <IL 0x0000c, 0x00077>
10-23 12:08:17.774 I/MonoDroid(23931): at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.LoadApplication (Xamarin.Forms.Application) <IL 0x00159, 0x003d3>
10-23 12:08:17.774 I/MonoDroid(23931): at _123SmartBMS.MainActivity.OnCreate (Android.OS.Bundle) [0x00089] in D:\bla\Apps\xxx\xxx.Android\MainActivity.cs:61
10-23 12:08:17.774 I/MonoDroid(23931): at Android.Support.V4.App.FragmentActivity.n_OnCreate_Landroid_os_Bundle_ (intptr,intptr,intptr) <IL 0x00013, 0x000ef>
10-23 12:08:17.774 I/MonoDroid(23931): at (wrapper dynamic-method) object.ae615951-826d-48aa-a3b4-478f7c8a6127 (intptr,intptr,intptr) <IL 0x00017, 0x00043>
10-23 12:08:17.781 W/art     (23931): JNI RegisterNativeMethods: attempt to register 0 native methods for md52ce486a14f4bcd95899665e9d932190b.JavaProxyThrowable

In my App I have something like this code:

public App(){
var dashNav = GetDashboard();


public static Page GetDashboardPage()
            var _dashboard = new DashboardPage(AppViewModel.DashboardViewModel);
            _navigationPage = new NavigationPage(_dashboard);
            _settingsToolbarItem = new ToolbarItem(Device.OnPlatform("Settings", string.Empty, ""), Device.OnPlatform(null, "settingsicon.png", ""), () =>
            _navigationPage.Title = _dashboard.Title;
            return _navigationPage;
Comment 1 Samantha Houts [MSFT] 2016-04-13 19:08:30 UTC
Thank you for your bug report. We believe there may have been a missed step in your conversion to AppCompat. If you are still experiencing the issue, please reopen this report with an attached reproduction.

Warm regards,
Xamarin Forms Team
Comment 2 Rogier van der Hee 2016-04-13 19:28:25 UTC
You are correct, in the mean time I have resolved this issue myself by carefully redoing the conversion steps. AppCompat has improved considerably also in the meantime.