Bug 46563 - Adding ListView in Custom control crashes in Android
Summary: Adding ListView in Custom control crashes in Android
Alias: None
Product: Forms
Classification: Xamarin
Component: Android ()
Version: 2.3.1
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: David Ortinau [MSFT]
Depends on:
Reported: 2016-11-08 09:20 UTC by Paul Anderson
Modified: 2017-06-19 21:46 UTC (History)
10 users (show)

Is this bug a regression?: ---
Last known good build:

A simple sample is created using the custom control (1.49 MB, application/zip)
2016-11-15 05:26 UTC, Paul Anderson

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 46563 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:

Description Paul Anderson 2016-11-08 09:20:57 UTC
This code works fine on iOS and UWP however on android it crashes. If I comment out the mainStack.Children.Add(listView) line all works ok. In Addition to the above, the same code works fine with Xamarin old version( after updating to the latest one this crashes occurs.

From output window
10-14 19:53:33.768 D/Mono ( 2550): Found as 'java_interop_jnienv_call_void_method'.
10-14 19:53:33.772 D/Mono ( 2550): Assembly Ref addref Xamarin.Forms.Platform.Android[0xa3ad5f80] -> Xamarin.Android.Support.v7.AppCompat[0xa3ad5b60]: 2
Unhandled Exception:

System.NullReferenceException: Object reference not set to an instance of an object.

10-14 19:53:40.964 D/Mono ( 2550): [0x8f47f920] worker finishing
Thread finished: #3
The thread 'Unknown' (0x3) has exited with code 0 (0x0).

From call stack
0x118 in Xamarin.Forms.Platform.Android.VisualElementRenderer<Xamarin.Forms.View>.SetElement at C:\BuildAgent2\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:193,5 C#
0x2E in Xamarin.Forms.Platform.Android.VisualElementRenderer<Xamarin.Forms.View>.Xamarin.Forms.Platform.Android.IVisualElementRenderer.SetElement at C:\BuildAgent2\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:126,4 C#
0x21 in Xamarin.Forms.Platform.Android.Platform.CreateRenderer at C:\BuildAgent2\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\Platform.cs:289,4 C#
0xFC in Xamarin.Forms.Platform.Android.VisualElementRenderer<Syncfusion.SfNavigationDrawer.XForms.SfNavigationDrawer>.SetElement at C:\BuildAgent2\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:190,4 C#
0x2E in Xamarin.Forms.Platform.Android.VisualElementRenderer<Syncfusion.SfNavigationDrawer.XForms.SfNavigationDrawer>.Xamarin.Forms.Platform.Android.IVisualElementRenderer.SetElement at C:\BuildAgent2\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:126,4 C#
0x21 in Xamarin.Forms.Platform.Android.Platform.CreateRenderer at C:\BuildAgent2\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\Platform.cs:289,4 C#

public View getDrawerContent()
StackLayout mainStack = new StackLayout();
mainStack.Opacity = 1;
mainStack.Orientation = StackOrientation.Vertical;
mainStack.HeightRequest = 500;
mainStack.BackgroundColor = Color.White;

        /*ObservableCollection<String> list = new ObservableCollection<string>();
        list.Add("Health Data");

        ListView listView = new ListView();

        listView.WidthRequest = 50;
        listView.VerticalOptions = LayoutOptions.FillAndExpand;
        listView.ItemsSource = new string[]{
"Health Data",


        listView.ItemSelected += ListView_ItemSelected;
        return mainStack;
Comment 1 adrianknight89 2016-11-08 15:04:55 UTC
Can you attach a project instead of a code snippet?
Comment 2 Paul Anderson 2016-11-15 05:26:29 UTC
Created attachment 18463 [details]
A simple sample is created using the custom control

Please run the sample in newer version of Xamarin.Forms(
Comment 3 Paul Anderson 2016-11-15 05:28:44 UTC
Sample is attached as per your request please check.
Comment 4 adrianknight89 2016-11-27 21:56:13 UTC
I don't have access to Syncfusion. Are you able to create a simpler repro without that library? I suspect that SetElement is passed a null object. This might be a problem with the library you're using rather than XF.
Comment 5 adrianknight89 2016-11-27 21:58:08 UTC
Ugh. Nvm. Just noticed that you're from SF. :) I'll check what was changed after
Comment 6 adrianknight89 2016-11-27 22:21:31 UTC
I'm not sure if your issue is at all related to this: https://bugzilla.xamarin.com/show_bug.cgi?id=47911, but it's something to keep in mind. If you are implementing a custom carousel view, make sure the items have a Parent & Platform.

Can you attach a repro with the missing dlls so I can compile and run it? Otherwise XF team can pick this up :)
Comment 7 Paul Anderson 2016-11-29 05:03:13 UTC

The issue have resolved now, thank you for your updates.
Comment 8 Paul Anderson 2016-12-16 08:43:01 UTC

The issue is still persists even after updating to Xamarin.Forms version works well in and older version).
Comment 9 Paul Anderson 2016-12-16 08:46:08 UTC
Sorry for the misconception it is Xamarin.Forms version and
Comment 10 adrianknight89 2016-12-16 16:11:53 UTC
Did you update to 2.3.3(not 1).175? Does the issue exist there?
Comment 11 Paul Anderson 2016-12-20 07:22:15 UTC
Yes,I have updated to the latest version(,but still the issue persists.
Comment 12 Namyslaw Szymaniuk 2017-01-16 10:41:36 UTC
Issue occurs also to me, at, as well as at lestest pre version, when I'm using Syncfusion SfNavigationDrawer.

It's reproducible even at sample project, delivered by Syncfusion - http://files2.syncfusion.com/Xamarin.Forms/Samples/NavigationDrawer_GettingStarted.zip

When I'm not puting ListView into SfNavigationDrawer, there is no issue.
Comment 13 Halil Dogan Bolak 2017-04-11 12:54:19 UTC
Same problem persists with Xamarin.Forms and Syncfusion !
Comment 14 Chris King 2017-06-19 16:37:16 UTC
Assigned to you because it was resolved by a customer.