Bug 25640 - Can't delete multiple ListView items from a ConextAction
Summary: Can't delete multiple ListView items from a ConextAction
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 1.3.0
Hardware: PC Mac OS
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2014-12-29 12:53 UTC by Sten
Modified: 2015-01-26 03:16 UTC (History)
4 users (show)

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

A test solution (25.81 KB, application/zip)
2015-01-15 12:40 UTC, Sten

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 Sten 2014-12-29 12:53:08 UTC
I have a list with related items, more than one may need to be deleted from the list when certain entries are deleted.

* Setup:

<ListView ItemsSource="{Binding Items}">
         <MenuItem Text="Delete" Command="{Binding DeleteCommand}" IsDestructive="true" />

* Attempted delete:

editorNode.DeleteCommand = new Command((prm) =>
  List<Node> relatedNodes = editorNode.FindRelatedNodes();
  relatedNodes.ForEach(rn=>Items.Remove(rn)); // Items is the ItemsSource observable collection

this code throws some odd exception, index out of bounds

* Workaround:
editorNode.DeleteCommand = new Command((prm) =>
        List<Node> relatedNodes = editorNode.FindRelatedNodes();

        Task.Delay(50) // without this delay there's an exception
            .ContinueWith(_ =>
                foreach (var dn in relatedNodes)
                    Device.BeginInvokeOnMainThread(() => Items.Remove(dn));
                    Task.Delay(10).Wait(); // without this delay there's an exception
Comment 1 Parmendra Kumar 2014-12-31 06:12:59 UTC
I have checked this issue but I am not able to reproduce this issue,  I have followed the instruction mentioned in the bug description. Could you Please provide us sample project, Environment info and Application output log. So that we can reproduce it at our end.
Comment 2 Sten 2015-01-15 12:38:46 UTC
The bug shows up with Xamarin.Forms.Labs.Controls.AutoCompleteView. Typing in the entry box of an AutoCompleteView causes the app to crash.

The exception thrown is:

MonoTouch.Foundation.MonoTouchException: Objective-C exception thrown.  Name: NSInternalInconsistencyException Reason: Invalid update: invalid number of rows in section 0.  The number of rows contained in an existing section after the update (1) must be equal to the number of rows contained in that section before the update (1), plus or minus the number of rows inserted or deleted from that section (1 inserted, 0 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).
  at MonoTouch.ObjCRuntime.Runtime.ThrowNSException (IntPtr ns_exception) [0x00000] in /Developer/MonoTouch/Source/maccore/src/ObjCRuntime/Runtime.cs:156
  at MonoTouch.ObjCRuntime.Runtime.throw_ns_exception (IntPtr exc) [0x00000] in /Developer/MonoTouch/Source/maccore/runtime/Delegates.generated.cs:100
  at at (wrapper native-to-managed) MonoTouch.ObjCRuntime.Runtime:throw_ns_exception (intptr)
  at at (wrapper managed-to-native) MonoTouch.ObjCRuntime.Messaging:void_objc_msgSend (intptr,intptr)
  at MonoTouch.UIKit.UITableView.EndUpdates () [0x00008] in /Developer/MonoTouch/Source/monotouch/src/build/compat/UIKit/UITableView.g.cs:255
  at Xamarin.Forms.Platform.iOS.ListViewRenderer.UpdateItems (System.Collections.Specialized.NotifyCollectionChangedEventArgs e, Int32 section, Boolean resetWhenGrouped) [0x00000] in <filename unknown>:0
  at Xamarin.Forms.Platform.iOS.ListViewRenderer+<>c__DisplayClass5.<OnCollectionChanged>b__4 () [0x00000] in <filename unknown>:0
  at MonoTouch.Foundation.NSAsyncActionDispatcher.Apply () [0x00000] in /Developer/MonoTouch/Source/maccore/src/Foundation/NSAction.cs:164
  at at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
  at MonoTouch.UIKit.UIApplication.Main (System.String[] args, IntPtr principal, IntPtr delegate) [0x00005] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:62
  at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:46
  at XamarinTesting.iOS.Application.Main (System.String[] args) [0x00008] in /Users/Sten/Projects/XamarinTesting/iOS/Main.cs:17
Comment 3 Sten 2015-01-15 12:40:12 UTC
Created attachment 9367 [details]
A test solution

Open the solution, start the iOS project and tap the second button "Test ListView ItemsSource changed Crash"
Comment 4 Sten 2015-01-15 13:43:34 UTC
Apparently the issue shows up only if more than one item is changed between renders. Adding or removing one item at a time doesn't cause the crash
Comment 5 Parmendra Kumar 2015-01-16 07:49:58 UTC
I have checked this issue and observed that when we have to click on search textbox the application crashed. 

Screencast: http://www.screencast.com/t/g57mH2O5EKD9

Please check the screencast and let me know if I have missed anything.

Output Log: https://gist.github.com/Parmendrak/38e71bfa300307b11bd2
Ide Log: https://gist.github.com/Parmendrak/afc042b75a8842fc5cd8
Buildoutput: https://gist.github.com/Parmendrak/42bba6b4ff6e4b6fc59e

Environment info:
=== Xamarin Studio ===

Version 5.7.1 (build 13)
Installation UUID: 1a096c6f-0678-402e-89b2-a2c10f7e80e4
	Mono 3.12.0 ((detached/a813491)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 312000068

=== Apple Developer Tools ===

Xcode 6.1 (6602)
Build 6A1052c

=== Xamarin.iOS ===

Version: (Enterprise Edition)
Hash: dfb682f
Build date: 2015-01-08 13:39:32-0500

=== Xamarin.Mac ===

Version: (Enterprise Edition)

=== Xamarin.Android ===

Version: (Enterprise Edition)
Android SDK: /Users/360_macmini/Desktop/android-sdk-macosx
	Supported Android versions:
		2.1    (API level 7)
		2.2    (API level 8)
		2.3    (API level 10)
		3.1    (API level 12)
		4.0    (API level 14)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
Java SDK: /usr
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

=== Build Information ===

Release ID: 507010013
Git revision: 8e357d6be321e716f361ebc9591e4cee7f217c21
Build date: 2015-01-15 14:23:22-05
Xamarin addins: a6842a7727f64e956f942b8160f7835c9d9076a4

=== Operating System ===

Mac OS X 10.9.4
Darwin ShrutiMac.local 13.3.0 Darwin Kernel Version 13.3.0
    Tue Jun  3 21:27:35 PDT 2014
    root:xnu-2422.110.17~1/RELEASE_X86_64 x86_64
Comment 6 Sten 2015-01-16 10:08:47 UTC
Typing in the entry box also crashes the app
Comment 7 Jason Smith [MSFT] 2015-01-26 03:16:45 UTC
This should be resolved in 1.3.2-pre1

If you can reproduce the issue please re-open.