Bug 42832 - Scrolling in ListView with active ContextActions causes System.NullReferenceException
Summary: Scrolling in ListView with active ContextActions causes System.NullReferenceE...
Alias: None
Product: Forms
Classification: Xamarin
Component: Android ()
Version: 2.3.2
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2016-07-27 10:37 UTC by Markus.Rollmann
Modified: 2016-11-09 22:18 UTC (History)
6 users (show)

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

repro project (58.71 KB, application/zip)
2016-08-19 16:30 UTC, Jimmy [MSFT]
Reproduction project (286.02 KB, application/x-zip-compressed)
2016-11-07 16:34 UTC, c.krempp91

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 Markus.Rollmann 2016-07-27 10:37:41 UTC
The listview caching strategy have to be "Recycle element"
Select an item in a listview with context actions with a long click. then on android the context action bar appears on the top, and the selected item gets a blue background. Now scoll a few times down and up, so that the selected item is scrolled out of diplay and comes again on display. This causes a crash with a System.NullReferenceException.
Comment 1 Rui Marinho 2016-08-10 16:21:22 UTC
Thank you for taking the time to submit this report. After reviewing the description of this bug, we believe it no longer affects the current version of Xamarin.Forms. If you are still experiencing the issue after updating your packages for the latest pre release 2.3.2-pre1, please reopen this report with an attached reproduction.

For your convenience, we have created some reproduction best practices viewable here: https://gist.github.com/jassmith/92405c300e54a01dcc6d

Warm regards, 
Xamarin Forms Team
Comment 2 Jimmy [MSFT] 2016-08-19 16:30:44 UTC
Created attachment 17127 [details]
repro project

I can still reproduce the crash with Forms 2.3.2-pre1. I've attached a repro project.

### Steps to Reproduce
1. Run the attached Android project
2. Long press a list item to open the context actions
3. Scroll the ListView around

### Expected Results
No app crash

### Actual Results
The app will crash. It appears to happen when the selected item is displayed on screen again then scrolled offscreen.
Comment 3 Jimmy [MSFT] 2016-08-19 16:32:21 UTC
Reopening due to comment 2
Comment 4 Rui Marinho 2016-10-17 18:00:00 UTC
Should be fixed in 2.3.4-pre1
Comment 5 Hrafn Loftsson 2016-10-28 10:10:40 UTC
A similar bug is in iOS.  When activating a context action (delete) in a listview and scrolling up/down, you get the following:

System.ArgumentNullException has been thrown
Value cannot be null.
Parameter name: gestureRecognizer

I have made a test project which shows this behavior: https://github.com/KolibriDev/TestLayoutXaml
Comment 6 c.krempp91 2016-11-07 16:34:16 UTC
Created attachment 18355 [details]
Reproduction project

This is a reproduction of the issue(s) described.
Comment 7 c.krempp91 2016-11-07 16:35:25 UTC
I have not been able to test against 2.3.4-pre1, but I was testing against I noticed this issue, and one other which I believe has a very similar root cause. The second issue I found was that if you have the context action bar present and perform an orientation change, the amount of times varies but 1 - 2 times should do it, the app will crash. From what I can gather these issues only occur when certain conditions are met: 

First, ListViewCachingStrategy.RecycleElement needs to be set for the ListView.

Second, You have to be using data binding for the crash to occur. If you just have a ListView that contains views without any BindingContext the crash does not occur. 

I have added a test project as well which should exhibit both issues: