I have 2 collection views that are shown by toggling 2 buttons on a form. When switching between them, iOS throws an exception. Works fine on Android.
I have seen an exception thrown from here as well...
The top level Load() call wraps everything with Xamarin.Forms.Device.BeginInvokeOnMainThread
.
Download sample code to reproduce the issue from my GitHub page. This code was created today with File/New Project
(so it's not anything legacy related).
none at this time
I had the same problem on iOS phones, tablets were just fine.
While this is a issue that needs to be address, what seemed to work for me was
Items = new Observerable<Class>()
Thanks for the tip. I tried Items = new ObservableCollection<T>()
just now (instead of Items.Clear()
). I didn't get the error, but the collectionviews don't show anything. I was hopeful that would work, but it didn't.
Thanks for the tip. I tried
Items = new ObservableCollection<T>()
just now (instead ofItems.Clear()
). I didn't get the error, but the collectionviews don't show anything. I was hopeful that would work, but it didn't.
You did add the SetField(ref _items, value) for the ObservableCollection? (just to confirm)
I noticed this was labeled for the 5.0.0 milestone. It's critical we get this working soon as we are stuck on XF 4.5 until it gets resolved.
XF 4.5 has the depricated UIWebView. This will prevent us from updating our app starting in December 2020.
I did confirm the latest XF does not have the depricated UIWebView issue, so we need to get to that version quickly so we can ferret out any other issues we might encounter before December 2020.
Can this fix be bumped to an earlier release other than v5?
Thanks for the tip. I tried
Items = new ObservableCollection<T>()
just now (instead ofItems.Clear()
). I didn't get the error, but the collectionviews don't show anything. I was hopeful that would work, but it didn't.You did add the SetField(ref _items, value) for the ObservableCollection? (just to confirm)
I didn't, but just tried that and it fixed the crash. I still have some weird display issues where both panes have to be Visible in order for the collection view to render properly, but I think I can work around that. Thanks for the tip!
This issue does need to be resolved however. It's definitely a bug. I would think many would be encountering it? The example reflects a common design pattern for Xamarin apps.
You are welcome 馃憤
I do however agree that this does need to be fixed so for everyone else that has the same issue.
For the MS team. There is another issue shown in this same example. Both issues might be related, not sure.
There are two ContentViews that are alternately displayed depending on which button is clicked at the bottom of the screen. The buttons toggle the ContentView IsVisible property true/false making it show/not show.
When the app comes up the collectionview on the panel that is not visible doesn't show it's contents properly. Only by using @NLGhofman suggestion above to new the collection each time, combined with initially making ALL the ContentViews visible solve the issue. Here is what it looks like when you click the Meters button the first time. There are some very faint dots that I believe are the collectionview trying to render itself.
Once you toggle back and forth (again, with @NLGhofman suggestion in place), they show up normally.
So the other issue is when the CollectionView is on a form not visible, it doesn't load properly. This is very problematic for our application, for in one section, it's a single page that shows/hides ContentViews based on tabs that are selected. To get around this bug, I think we will have to show every panel IsVisible=true on initialization, load all the collectionviews, and then hide the panels. At a minimum this will create anti-patterns just to get around this problem. Ultimately it will lead to an intractable situation where the app just doesn't work until this bug is fixed.
With the iOS UIWebView deadline looming, this is a red hot issue for us. I have been reconfiguring our app to show all panels upon startup, load them all, and then hide them as needed. It's working better, but still not consistent. At this point there is no workaround. I would appreciate an update on when this will be fixed please.
I can confirm that this happens on 4.7.0.1351. I was able to work around by not calling Clear()
and instead using a new observable.
We're now getting this as well in a production App. Please fix.
Same here, we now added a work around but it would be better to have this fixed.
Multiple crashes here also when clearing a collection, this should not lead to crash.
This is such a basic functionality, please prioritize this
Just to confirm, what steps are required to workaround this bug?
SetField(ref _items, value) ?
Replace Items.Clear() with Items = new ObservableCollection
TIA
Just to confirm, what steps are required to workaround this bug?
SetField(ref _items, value) ?
Replace Items.Clear() with Items = new ObservableCollection() ?
TIA
Yes, that should work for a workaround :)
The "Setfield(ref _items, value)" was cause the original writer didn't have the binding set.
with kind regards,
@lafritay @hartez When trying to work-around this with replacing the collection the following occurs https://github.com/xamarin/Xamarin.Forms/issues/8308
Any solution? at the moment all usages to collection views are leading to crashes
@jormenjanssen I have a number of workarounds in place and I think I've got it to a point where it can limp along. I just posted them here: https://github.com/xamarin/Xamarin.Forms/issues/8308#issuecomment-713854725. @hartez if you get a chance to look at the workarounds and give your opinion if they are safe or not, that would likely help a number of us.
We get the error on Android 10 too
Same here, sporadically.
Just adding a me too here... going to try swapping out the observable instead of clearing it with proper property changed feedback and will let you know
To follow up - it seems like clearing an observable collection and then adding the items (like in the case of a selection) is causing the issue. I've pulled a stacktrace if this is of any use.
Workaround:
``` C#
...
// ViewModel
ObservableCollection
public ObservableCollection
{
get => _selectedStores;
set => SetProperty(ref _selectedStores, value);
}
...
// After selection event
SelectedStores = new ObservableCollection
.OrderBy(x => x.Coordinates.GetDistance(MyLocation))
.Distinct());
...
Here's my old stacktrace when I did a clear and then AddRange (custom extension)
``
Unhandled Exception:
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
at System.Collections.Generic.List
1[T].get_Item (System.Int32 index) [0x00009] in <85a0be741dba4068b8b83c4563af7fa8>:0
at System.Collections.ObjectModel.Collection`1[T].System.Collections.IList.get_Item (System.Int32 index) [0x00000] in <85a0be741dba4068b8b83c4563af7fa8>:0
at Xamarin.Forms.Platform.iOS.ObservableItemsSource.ElementAt (System.Int32 index) [0x0000f] in D:a1sXamarin.Forms.Platform.iOSCollectionViewObservableItemsSource.cs:254
at Xamarin.Forms.Platform.iOS.ObservableItemsSource.get_Item (System.Int32 index) [0x00000] in D:a1sXamarin.Forms.Platform.iOSCollectionViewObservableItemsSource.cs:40
at Xamarin.Forms.Platform.iOS.ObservableItemsSource.get_Item (Foundation.NSIndexPath indexPath) [0x00019] in D:a1sXamarin.Forms.Platform.iOSCollectionViewObservaThread started:
bleItemsSource.cs:96
at Xamarin.Forms.Platform.iOS.ItemsViewController1[TItemsView].UpdateTemplatedCell (Xamarin.Forms.Platform.iOS.TemplatedCell cell, Foundation.NSIndexPath indexPath) [0x00029] in <2fc4c3454b1b4d7c83cbd4885fce6d6f>:0
at Xamarin.Forms.Platform.iOS.ItemsViewController
1[TItemsView].GetCell (UIKit.UICollectionView collectionView, Foundation.NSIndexPath indexPath) [0x00033] in <2fc4c3454b1b4d7c83cbd4885fce6d6f>:0
at Xamarin.Forms.Platform.iOS.ItemsViewController`1[TItemsView].GetPrototype () [0x00064] in <2fc4c3454b1b4d7c83cbd4885fce6d6f>:0
at Xamarin.Forms.Platform.iOS.ItemsViewLayout.DetermineCellSize () [0x0004e] in D:a1sXamarin.Forms.Platform.iOSCollectionViewItemsViewLayout.cs:201
at Xamarin.Forms.Platform.iOS.ListViewLayout.ConstrainTo (CoreGraphics.CGSize size) [0x0001e] in D:a1sXamarin.Forms.Platform.iOSCollectionViewListViewLayout.cs:16
at Xamarin.Forms.Platform.iOS.ItemsViewLayout.UpdateConstraints (CoreGraphics.CGSize size) [0x0003f] in D:a1sXamarin
.Forms.Platform.iOSCollectionViewItemsViewLayout.cs:96
at Xamarin.Forms.Platform.iOS.ItemsViewLayout.InvalidateLayout () [0x00000] in D:a1sXamarin.Forms.Platform.iOSCollectionViewItemsViewLayout.cs:535
at (wrapper managed-to-native) ObjCRuntime.Messaging.void_objc_msgSend(intptr,intptr)
at UIKit.UICollectionView.ReloadData () [0x00008] in /Library/Frameworks/Xamarin.iOS.framework/Versions/14.2.0.12/src/Xamarin.iOS/UIKit/UICollectionView.g.cs:736
at Xamarin.Forms.Platform.iOS.ObservableItemsSource.Reload () [0x00071] in D:a1sXamarin.Forms.Platform.iOSCollectionViewObservableItemsSource.cs:142
at Xamarin.Forms.Platform.iOS.ObservableItemsSource.CollectionChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs args) [0x00198] in D:a1sXamarin.Forms.Platform.iOSCollectionViewObservableItemsSource.cs:129
at Xamarin.Forms.Platform.iOS.ObservableItemsSource.CollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs arg
ary/Frameworks/Xamarin.iOS.framework/Versions/14.2.0.12/src/Xamarin.iOS/UIKit/UIApplication.cs:65
at PolynMobile.iOS.Application.Main (System.String[] args) [0x00001] in D:ProjectsReactorPolynMobileApp.iOSMain.cs:17
s) [0x000b7] in D:a1sXamarin.Forms.Platform.iOSCollectionViewObservableItemsSource.cs:108
at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.
at Foundation.NSAsyncSynchronizationContextDispatcher.Apply () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/14.2.0.12/src/Xamarin.iOS/Foundation/NSAction.cs:178
at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Library/Frameworks/Xamarin.iOS.framework/Versions/14.2.0.12/src/Xamarin.iOS/UIKit/UIApplication.cs:86
at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0000e] in /Libr
2020-11-03 15:37:13.799 PolynMobile.iOS[574:46332] Unhandled managed exception: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index (System.ArgumentOutOfRangeException)
at System.Collections.Generic.List1[T].get_Item (System.Int32 index) [0x00009] in <85a0be741dba4068b8b83c4563af7fa8>:0
at System.Collections.ObjectModel.Collection
1[T].System.Collections.IList.get_Item (System.Int32 index) [0x00000] in <85a0be741dba4068b8b83c4563af7fa8>:0
at Xamarin.Forms.Platform.iOS.ObservableItemsSource.ElementAt (System.Int32 index) [0x0000f] in D:a1sXamarin.Forms.Platform.iOSCollectionViewObservableItemsSource.cs:254
at Xamarin.Forms.Platform.iOS.ObservableItemsSource.get_Item (System.Int32 index) [0x00000] in D:a1sXamarin.Forms.Platform.iOSCollectionViewObservableItemsSource.cs:40
at Xamarin.Forms.Platform.iOS.ObservableItemsSource.get_Item (Foundation.NSIndexPath indexPath) [0x00019] in D:a1sXamarin.Forms.Platform.iOSCollectionView
ObservableItemsSource.cs:96
at Xamarin.Forms.Platform.iOS.ItemsViewController1[TItemsView].UpdateTemplatedCell (Xamarin.Forms.Platform.iOS.TemplatedCell cell, Foundation.NSIndexPath indexPath) [0x00029] in <2fc4c3454b1b4d7c83cbd4885fce6d6f>:0
at Xamarin.Forms.Platform.iOS.ItemsViewController
1[TItemsView].GetCell (UIKit.UICollectionView collectionView, Foundation.NSIndexPath indexPath) [0x00033] in <2fc4c3454b1b4d7c83cbd4885fce6d6f>:0
at Xamarin.Forms.Platform.iOS.ItemsViewController`1[TItemsView].GetPrototype () [0x00064] in <2fc4c3454b1b4d7c83cbd4885fce6d6f>:0
at Xamarin.Forms.Platform.iOS.ItemsViewLayout.DetermineCellSize () [0x0004e] in D:a1sXamarin.Forms.Platform.iOSCollectionViewItemsViewLayout.cs:201
at Xamarin.Forms.Platform.iOS.ListViewLayout.ConstrainTo (CoreGraphics.CGSize size) [0x0001e] in D:a1sXamarin.Forms.Platform.iOSCollectionViewListViewLayout.cs:16
at Xamarin.Forms.Platform.iOS.ItemsViewLayout.UpdateConstraints (CoreGraphics.CGSize size) [0x0003f] in D:a1s
Xamarin.Forms.Platform.iOSCollectionViewItemsViewLayout.cs:96
at Xamarin.Forms.Platform.iOS.ItemsViewLayout.InvalidateLayout () [0x00000] in D:a1sXamarin.Forms.Platform.iOSCollectionViewItemsViewLayout.cs:535
at (wrapper managed-to-native) ObjCRuntime.Messaging.void_objc_msgSend(intptr,intptr)
at UIKit.UICollectionView.ReloadData () [0x00008] in /Library/Frameworks/Xamarin.iOS.framework/Versions/14.2.0.12/src/Xamarin.iOS/UIKit/UICollectionView.g.cs:736
at Xamarin.Forms.Platform.iOS.ObservableItemsSource.Reload () [0x00071] in D:a1sXamarin.Forms.Platform.iOSCollectionViewObservableItemsSource.cs:142
at Xamarin.Forms.Platform.iOS.ObservableItemsSource.CollectionChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs args) [0x00198] in D:a1sXamarin.Forms.Platform.iOSCollectionViewObservableItemsSource.cs:129
at Xamarin.Forms.Platform.iOS.ObservableItemsSource.CollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEvent
Args args) [0x000b7] in D:a1sXamarin.Forms.Platform.iOSCollectionViewObservableItemsSource.cs:108
at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.
at Foundation.NSAsyncSynchronizationContextDispatcher.Apply () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/14.2.0.12/src/Xamarin.iOS/Foundation/NSAction.cs:178
at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Library/Frameworks/Xamarin.iOS.framework/Versions/14.2.0.12/src/Xamarin.iOS/UIKit/UIApplication.cs:86
at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0000e]
0x106c220c0 - /private/var/containers/Bundle/Application/021E6193-52B5-4C02-9C77-78A2A9DCB233/PolynMobile.iOS.app/PolynMobile.iOS :
0x106c18d5c - /private/var/containers/Bundle/Application/021E6193-52B5-4C02-9C77-78A2A9DCB233/PolynMobile.iOS.app/PolynMobile.iOS :
in /Library/Frameworks/Xamarin.iOS.framework/Versions/14.2.0.12/src/Xamarin.iOS/UIKit/UIApplication.cs:65
at PolynMobile.iOS.Application.Main (System.String[] args) [0x00001] in D:ProjectsReactorPolynMobileApp.iOSMain.cs:17
=================================================================
Got a abrt while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
=================================================================
0x106c2160c - /private/var/containers/Bundle/Application/021E6193-52B5-4C02-9C77-78A2A9DCB233/PolynMobile.iOS.app/PolynMobile.iOS :
0x1ed9e2dbc - /usr/lib/system/libsystem_platform.dylib : <redacted>
0x1ed9f29e8 - /usr/lib/system/libsystem_pthread.dylib : pthread_kill
0x1b08ff934 - /usr/lib/system/libsystem_c.dylib : abort
0x106d5fca0 - /private/var/containers/Bundle/Application/021E6193-52B5-4C02-9C77-78A2A9DCB233/PolynMobile.iOS.app/PolynMobile.iOS : xamarin_get_block_descriptor
0x104c05a1c - /private/var/containers/Bundle/Application/021E6193-52B5-4C02-9C77-78A2A9DCB233/PolynMobile.iOS.app/PolynMobile.iOS :
0x1049b24cc - /private/var/containers/Bundle/Application/021E6193-52B5-4C02-9C77-78A2A9DCB233/PolynMobile.iOS.app/PolynMobile.iOS :
0x106c77bf8 - /private/var/containers/Bundle/Application/021E6193-52B5-4C02-9C77-78A2A9DCB233/PolynMobile.iOS.app/PolynMobile.iOS : mono_pmip
0x106c1898c - /private/var/containers/Bundle/Application/021E6193-52B5-4C02-9C77-78A2A9DCB233/PolynMobile.iOS.app/PolynMobile.iOS :
0x106c17374 - /private/var/containers/Bundle/Application/021E6193-52B5-4C02-9C77-78A2A9DCB233/PolynMobile.iOS.app/PolynMobile.iOS :
0x106c0e698 - /private/var/containers/Bundle/Application/021E6193-52B5-4C02-9C77-78A2A9DCB233/PolynMobile.iOS.app/PolynMobile.iOS :
0x1049b8584 - /private/var/containers/Bundle/Application/021E6193-52B5-4C02-9C77-78A2A9DCB233/PolynMobile.iOS.app/PolynMobile.iOS :
0x1057478dc - /private/var/containers/Bundle/Application/021E6193-52B5-4C02-9C77-78A2A9DCB233/PolynMobile.iOS.app/PolynMobile.iOS :
0x104bc71d0 - /private/var/containers/Bundle/Application/021E6193-52B5-4C02-9C77-78A2A9DCB233/PolynMobile.iOS.app/PolynMobile.iOS :
0x106cc46f0 - /private/var/containers/Bundle/Application/021E6193-52B5-4C02-9C77-78A2A9DCB233/PolynMobile.iOS.app/PolynMobile.iOS : mono_pmip
0x104816650 - /private/var/containers/Bundle/Application/021E6193-52B5-4C02-9C77-78A2A9DCB233/PolynMobile.iOS.app/PolynMobile.iOS :
0x106c28cd8 - /private/var/containers/Bundle/Application/021E6193-52B5-4C02-9C77-78A2A9DCB233/PolynMobile.iOS.app/PolynMobile.iOS : mono_pmip
0x106cc1288 - /private/var/containers/Bundle/Application/021E6193-52B5-4C02-9C77-78A2A9DCB233/PolynMobile.iOS.app/PolynMobile.iOS : mono_pmip
0x10481830c - /private/var/containers/Bundle/Application/021E6193-52B5-4C02-9C77-78A2A9DCB233/PolynMobile.iOS.app/PolynMobile.iOS :
0x1a8f68da0 - /System/Library/Frameworks/Foundation.framework/Foundation : <redacted>
0x1a7c05240 - /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation : <redacted>
0x1a7c05140 - /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation : <redacted>
0x1a7c04488 - /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation : <redacted>
0x1a7bfea40 - /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation : <redacted>
0x1a7bfe200 - /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation : CFRunLoopRunSpecific
0x1bdd7b598 - /System/Library/PrivateFrameworks/GraphicsServices.framework/GraphicsServices : GSEventRunModal
0x1aa4c7bcc - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : <redacted>
0x1aa4cd1a0 - /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore : UIApplicationMain
0x10579b588 - /private/var/containers/Bundle/Application/021E6193-52B5-4C02-9C77-78A2A9DCB233/PolynMobile.iOS.app/PolynMobile.iOS :
Thread started:
0x1056f7a80 - /private/var/containers/Bundle/Application/021E6193-52B5-4C02-9C77-78A2A9DCB233/PolynMobile.iOS.app/PolynMobile.iOS :
0x1056f7a04 - /private/var/containers/Bundle/Application/021E6193-52B5-4C02-9C77-78A2A9DCB233/PolynMobile.iOS.app/PolynMobile.iOS :
0x1048425e0 - /private/var/containers/Bundle/Application/021E6193-52B5-4C02-9C77-78A2A9DCB233/PolynMobile.iOS.app/PolynMobile.iOS :
0x104bc71d0 - /private/var/containers/Bundle/Application/021E6193-52B5-4C02-9C77-78A2A9DCB233/PolynMobile.iOS.app/PolynMobile.iOS :
0x106c28cd8 - /private/var/containers/Bundle/Application/021E6193-52B5-4C02-9C77-78A2A9DCB233/PolynMobile.iOS.app/PolynMobile.iOS : mono_pmip
0x106cc1288 - /private/var/containers/Bundle/Application/021E6193-52B5-4C02-9C77-78A2A9DCB233/PolynMobile.iOS.app/PolynMobile.iOS : mono_pmip
0x106cc6380 - /private/var/containers/Bundle/Application/021E6193-52B5-4C02-9C77-78A2A9DCB233/PolynMobile.iOS.app/PolynMobile.iOS : mono_pmip
0x106c0e1d8 - /private/var/containers/Bundle/Application/021E6193-52B5-4C02-9C77-78A2A9DCB233/PolynMobile.iOS.app/PolynMobile.iOS :
0x106d6f2c0 - /private/var/containers/Bundle/Application/021E6193-52B5-4C02-9C77-78A2A9DCB233/PolynMobile.iOS.app/PolynMobile.iOS : _Z9__isctypeim
0x1048424e4 - /private/var/containers/Bundle/Application/021E6193-52B5-4C02-9C77-78A2A9DCB233/PolynMobile.iOS.app/PolynMobile.iOS :
0x1a78dd588 - /usr/lib/system/libdyld.dylib : <redacted>
=================================================================
Memory around native instruction pointer (0x1d282295c):0x1d282294c c0
03 5f
d6
c0 03 5f
d6 10 29
80 d2 01 10 00
d4 .
._
..
._
..)
...
...
0x1d282295c
e3 00
00 54 fd
7b bf
a9 fd 03
00 91 1d
76 ff 97
..
.
T.{.
..
...
.v
..
03
0x1d282296c bf
00 91 fd
7b
c1
a8 c0
03 5f d6 c0
03 5f d6 .
....
{.
..
._.
..
_.
0x1d282297c
90 29
80 d2 01
10
00 d4 e3 00 00 54
fd 7b bf a9
.)
...
..
..
..T.
{.
.
=================================================================
=================================================================
I am seeing this on Xamarin.Forms version 4.7.0.968 with iOS on a CollectionView. I might be able to provide a reproduction if that will help.
I agree with the assessment here https://github.com/xamarin/Xamarin.Forms/issues/12080#issuecomment-721387131 as I am getting bugs reported when we select an item on the CollectionView.
Same issue, XF 4.8.1687 and iOS 13.7 and iOS 14.2
This is a super critical bug, how does stuff like this keep slipping out, they busy doing podcasts and videos talking about XF5.0 yet they keep releasing garbage.
Same issue, XF 4.8.1687 and iOS 13.7 and iOS 14.2
This is a super critical bug, how does stuff like this keep slipping out, they busy doing podcasts and videos talking about XF5.0 yet they keep releasing garbage.
Easy:) you are not their main customers :) Same issue 4.8.0.1687
Most helpful comment
Multiple crashes here also when clearing a collection, this should not lead to crash.
This is such a basic functionality, please prioritize this