Bug 25396 - NSInternalConsistencyException when bound to ObservableCollection
Summary: NSInternalConsistencyException when bound to ObservableCollection
Status: VERIFIED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms (show other bugs)
Version: 1.3.0
Hardware: Macintosh Mac OS
: Highest normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-12-15 12:21 UTC by Stuart Carnie
Modified: 2017-10-10 10:13 UTC (History)
12 users (show)

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


Attachments
Project that demonstrates issue (3.45 MB, application/zip)
2014-12-15 12:21 UTC, Stuart Carnie
Details
Re-attach with confirmed working build (3.45 MB, application/octet-stream)
2014-12-17 10:28 UTC, Stuart Carnie
Details

Description Stuart Carnie 2014-12-15 12:21:39 UTC
Created attachment 9076 [details]
Project that demonstrates issue

When updating an ObservableCollection that is bound to a ListView, an iOS application will always generate an NSInternalConsistencyException:

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 (2), 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).

Similar code (such as the MobileCRM application) on Xamarin.Forms 1.2.x works fine.
Comment 1 Parmendra Kumar 2014-12-17 10:00:32 UTC
I have checked this issue with attached sample but I am not able to deploy successfully on simulator/device. Please check the screencast and let we know if I have missed anything.
could you please provide me the new correct sample project?

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

Application Output: https://gist.github.com/Parmendrak/4de4f956ab504c683c66

Environment info:

Xamarin Studio 5.5.4 (build 15)
Xamarin.Android : 4.20.0.28 (Business Edition)
Xcode 6.1 (6602)
Xamarin.iOS: 8.4.0.47 (Business Edition)
Xamarin.Mac: 1.10.0.18 (Business Edition)
Mac OS X 10.9.4
Comment 2 Stuart Carnie 2014-12-17 10:28:02 UTC
Created attachment 9103 [details]
Re-attach with confirmed working build
Comment 3 Stuart Carnie 2014-12-17 10:28:31 UTC
I had no issues building and deploying. I'm running Xamarin Studio 5.7 if that helps
Comment 4 Parmendra Kumar 2014-12-19 10:17:41 UTC
Thanks Stuart,

I have checked this issue with new sample attached in comment 2 and able to run app successfully. I got an exception which is different from yours exception.

Screencast : http://www.screencast.com/t/QNoQqXs5w
ApplicationOutput: https://gist.github.com/Parmendrak/2c339f2f4927b1848898

Could you please let us know you are getting this exception with device or simulator? If possible please provide us complete environment info, device/simulator info and log and Application Output, so that developer can figure out what's going on from the stack trace.

Thanks!

Environment info:

=== Xamarin Studio ===

Version 5.7 (build 657)
Installation UUID: 1a096c6f-0678-402e-89b2-a2c10f7e80e4
Runtime:
	Mono 3.10.0 ((detached/92c4884)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 310000031

=== Apple Developer Tools ===

Xcode 6.1 (6602)
Build 6A1052c

=== Xamarin.iOS ===

Version: 8.6.0.36 (Business Edition)
Hash: fb82d4e
Branch: 
Build date: 2014-12-16 22:30:17-0500

=== Build Information ===

Release ID: 507000657
Git revision: 012ec6963a2949d3773b96cee5bc4a05dbada096
Build date: 2014-12-16 15:34:30-05
Xamarin addins: 39ab76ee8d2bc1539d561fd800123124d5ee8bdb

=== 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 5 Stuart Carnie 2014-12-19 13:19:16 UTC
Yes, after Xamarin Studio updated to the latest (5.7 build 652) , I am now seeing the same error as you. Here is output from About:

Xamarin Studio
Version 5.7 (build 652)
Installation UUID: 05118f15-eaf0-49aa-b448-142a23519d31
Runtime:
	Mono 3.12.0 ((detached/a813491)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 312000068

Apple Developer Tools
Xcode 6.1.1 (6611)
Build 6A2008a

Xamarin.iOS
Version: 8.6.0.32 (Indie Edition)
Hash: f31ad46
Branch: 
Build date: 2014-12-12 17:56:03-0500

Xamarin.Android
Not Installed

Xamarin.Mac
Version: 1.11.3.0 (Starter Edition)

Build Information
Release ID: 507000652
Git revision: 042e44ba92a6a9c46bd2b69b0b4348df43f381ea
Build date: 2014-12-11 18:37:24-05
Xamarin addins: 06d3aaafde7f726d508e079c9b297cc9aae4af55

Operating System
Mac OS X 10.10.1
Darwin scarnie-mbp.local 14.0.0 Darwin Kernel Version 14.0.0
    Fri Sep 19 00:26:44 PDT 2014
    root:xnu-2782.1.97~2/RELEASE_X86_64 x86_64
Comment 6 Stuart Carnie 2014-12-19 13:22:18 UTC
However, if you replace the TestListViewModel.LoadData method with the following:

		void LoadData() {
			//Rows = new ObservableCollection<Row> (new []{new Row{Name="one"}, new Row{Name="Two"}});

			Rows.Clear ();
			var rows = new ObservableCollection<Row> (new []{new Row{Name="one"}, new Row{Name="Two"}});
			foreach (var row in rows) {
				Rows.Add(row);
			}
		}

You will receive the NSInternalConsistencyException
Comment 7 Stuart Carnie 2014-12-25 11:02:21 UTC
Ignore the MethodNotFoundException, which was resolved with 1.3.1 due to incompatibilities with the unified framework. Now the only problem is the NSInternalConsistencyException
Comment 8 Parmendra Kumar 2014-12-29 09:16:19 UTC
I have checked this issue and follow the code mentioned in the comment 6, And I am also getting same exception "NSInternalInconsistencyException".

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

Application output: https://gist.github.com/Parmendrak/66ef463246db007ec632
Build Output: https://gist.github.com/Parmendrak/8914365788c20172ce60
Ide Log: https://gist.github.com/Parmendrak/d8b87f5368478960c8a7

Environment info:

=== Xamarin Studio ===

Version 5.7 (build 657)
Installation UUID: 1a096c6f-0678-402e-89b2-a2c10f7e80e4
Runtime:
	Mono 3.10.0 ((detached/92c4884)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 310000031

=== Apple Developer Tools ===

Xcode 6.1 (6602)
Build 6A1052c

=== Xamarin.iOS ===

Version: 8.6.0.36 (Enterprise Edition)
Hash: fb82d4e
Branch: 
Build date: 2014-12-16 22:30:17-0500

=== Xamarin.Android ===

Version: 4.20.0.28 (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)

=== Xamarin.Mac ===

Version: 1.10.0.18 (Enterprise Edition)

=== Build Information ===

Release ID: 507000657
Git revision: 012ec6963a2949d3773b96cee5bc4a05dbada096
Build date: 2014-12-16 15:34:30-05
Xamarin addins: 39ab76ee8d2bc1539d561fd800123124d5ee8bdb

=== 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 12 Jason Smith [MSFT] 2015-01-19 16:43:17 UTC
Should be fixed in 1.3.2-pre1
Comment 13 John Michael Hauck 2015-01-27 13:06:44 UTC
I confirmed 1.3.2.6299-pre1 fixed the problem for me here:
https://github.com/JohnMichaelHauck/XamarinFormsBug01/commit/e10d9436ae0d6e1002e3aca41f034efd3d179dee
Comment 14 Parmendra Kumar 2015-01-28 13:11:26 UTC
I have checked this issue with Xamarin.Forms 1.3.2.6299-pre1 and now Its working fine.

Hence closing this issue.
Comment 15 arx iT 2017-04-10 12:02:00 UTC
Hi, this bug is occuring again in XF 2.3.4.224, I reverted back to 2.3.3.193 and it's working fine. Bug appeared after updating.
Comment 16 Kyle 2017-10-05 05:02:03 UTC
As with arx iT I'm also having this problem again with the latest version of Forms. =( Anyone know a workaround I haven't been able to find one?
Comment 17 Jeroen 2017-10-10 10:13:46 UTC
Hi @Kyle, just updated to XF 2.4.0.282. Got this stack trace in the simulator. Any ideas?

Unhandled Exception:

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).
Native stack trace:
	0   CoreFoundation                      0x0000000112e9cd85 __exceptionPreprocess + 165
	1   libobjc.A.dylib                     0x00000001139a8deb objc_exception_throw + 48
	2   CoreFoundation                      0x0000000112e9cbea +[NSException raise:format:arguments:] + 106
	3   Foundation                          0x000000010c662d5a -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 198
	4   UIKit                               0x000000010adac4ca -[UITableView _endCellAnimationsWithContext:] + 15146
	5   HRoWorkAppiOS                       0x000000010a004b29 xamarin_dyn_objc_msgSend + 217
	6   ???                                 0x00000001261e45d2 0x0 + 4934485458
 occurred

Note You need to log in before you can comment on or make changes to this bug.