locked
Crash when removing items from ObservableCollection in XForms 1.3 RRS feed

  • Question

  • User22549 posted

    Hi all. I'm seeing a crash bug in iOS that I don't think existed in 1.2.3.

    The crash happens when removing items from an observable collection bound to a ListView in iOS (the code works perfectly in Android). The iOS main thread crashes with the following exception:

    Argument is out of range.
    Parameter name: index
    

    Stack trace:

      at Xamarin.Forms.ListProxy.get_Item (Int32 index) [0x00000] in <filename unknown>:0 
      at Xamarin.Forms.TemplatedItemsList`2[Xamarin.Forms.ItemsView`1[Xamarin.Forms.Cell],Xamarin.Forms.Cell].get_Item (Int32 index) [0x00000] in <filename unknown>:0 
      at Xamarin.Forms.Platform.iOS.ListViewRenderer+ListViewDataSource.GetCellForPath (MonoTouch.Foundation.NSIndexPath indexPath) [0x00000] in <filename unknown>:0 
      at Xamarin.Forms.Platform.iOS.ListViewRenderer+ListViewDataSource.GetCell (MonoTouch.UIKit.UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath) [0x00000] in <filename unknown>:0 
      at (wrapper managed-to-native) MonoTouch.ObjCRuntime.Messaging:void_objc_msgSend (intptr,intptr)
      at MonoTouch.UIKit.UITableView.EndUpdates () [0x00010] 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 (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 MyApp.iOS.Application.Main (System.String[] args) [0x00008] in /Users/me/Documents/Development/Xamarin/MyApp/iOS/Main.cs:17  
    
    Friday, January 9, 2015 10:28 PM

All replies

  • User80591 posted

    Even I am facing the same issue, please fix asap, else let us know the workaround to fix the same

    Friday, January 16, 2015 3:53 PM
  • User61458 posted

    Check out this thread for a workaround.

    http://forums.xamarin.com/discussion/comment/95976#Comment_95976

    Friday, January 16, 2015 6:54 PM
  • User22549 posted

    @AdamWolf? Thank you for your input, however this is not the problem I'm having. I also was having issues with the clear() function, and I mitigated it using the technique you linked to.

    I'm seeing this issue when trying to use the RemoveAt() function to filter an observable collection down based on search criteria.

    Thanks!

    Friday, January 16, 2015 7:45 PM
  • User531 posted

    I was experiencing this issue. The ObservableCollectionFast class introduced by Ian Vink in this thread did the trick. What worked for me was building up a List of the objects I wanted to keep in the ObservableCollection, then calling ObservableCollectionFast's Reset method with those objects. Anything else gave the "Argument is out of range." error.

    Tuesday, January 20, 2015 3:15 PM
  • User2496 posted

    Can you try with XF 1.3.2-pre1 ? thanks

    Tuesday, January 20, 2015 7:07 PM
  • User22549 posted

    Awesome, this totally fixed my issue. I also love it that it removes the animation of the list filling in each time a character was typed into the search box (in a type-ahead search implementation). Thanks @NaeemBari and @IanVink!

    Tuesday, January 20, 2015 7:42 PM
  • User22549 posted

    @rmarinho 1.3.2-pre1 also fixes the bug, thanks. However, really like @IanVink's solution for the additional features it adds.

    Tuesday, January 20, 2015 8:03 PM
  • User83890 posted

    Using XForms 1.3.2.6316 and XLabs 2.0.0 and I'm getting a very similar problem. I tried the suggestions noted above but nothing keeps my app from crashing. It makes no difference how the ObservableCollection is modified. I get the same result when I try to remove each element, call Clear() or simply dispose of the collection and create a new one altogether.

    The really interesting thing for me is that I was using XForms 1.3.2 and XLabs 1.2-pre with no problems and as soon as I upgraded to XLabs 2.0.0 I started seeing this issue.

    Help, please.

    System.ArgumentOutOfRangeException: Argument is out of range. Parameter name: index at System.Collections.Generic.List`1[Xamarin.Forms.Element].get_Item (Int32 index) [0x0000c] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Collections.Generic/List.cs:660 at System.Collections.ObjectModel.Collection`1[Xamarin.Forms.Element].get_Item (Int32 index) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Collections.ObjectModel/Collection.cs:154 at System.Collections.ObjectModel.ReadOnlyCollection`1[Xamarin.Forms.Element].get_Item (Int32 index) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Collections.ObjectModel/ReadOnlyCollection.cs:118 at Xamarin.Forms.Platform.iOS.RendererPool.UpdateRenderers (Xamarin.Forms.Element newElement) [0x00000] in <filename unknown>:0 at Xamarin.Forms.Platform.iOS.RendererPool.UpdateNewElement (Xamarin.Forms.VisualElement newElement) [0x00000] in <filename unknown>:0 at Xamarin.Forms.Platform.iOS.VisualElementPackager.SetElement (Xamarin.Forms.VisualElement oldElement, Xamarin.Forms.VisualElement newElement) [0x00000] in <filename unknown>:0 at Xamarin.Forms.Platform.iOS.VisualElementPackager.OnRendererElementChanged (System.Object sender, Xamarin.Forms.Platform.iOS.VisualElementChangedEventArgs args) [0x00000] in <filename unknown>:0 at at (wrapper delegate-invoke) System.EventHandler`1<Xamarin.Forms.Platform.iOS.VisualElementChangedEventArgs>:invoke_void_object_TEventArgs (object,Xamarin.Forms.Platform.iOS.VisualElementChangedEventArgs) at at (wrapper delegate-invoke) System.EventHandler`1<Xamarin.Forms.Platform.iOS.VisualElementChangedEventArgs>:invoke_void_object_TEventArgs (object,Xamarin.Forms.Platform.iOS.VisualElementChangedEventArgs) at at (wrapper delegate-invoke) System.EventHandler`1<Xamarin.Forms.Platform.iOS.VisualElementChangedEventArgs>:invoke_void_object_TEventArgs (object,Xamarin.Forms.Platform.iOS.VisualElementChangedEventArgs) at Xamarin.Forms.Platform.iOS.ScrollViewRenderer.OnElementChanged (Xamarin.Forms.Platform.iOS.VisualElementChangedEventArgs e) [0x00000] in <filename unknown>:0 at Xamarin.Forms.Platform.iOS.ScrollViewRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00000] in <filename unknown>:0 at Xamarin.Forms.Platform.iOS.RendererPool.UpdateRenderers (Xamarin.Forms.Element newElement) [0x00000] in <filename unknown>:0 at Xamarin.Forms.Platform.iOS.RendererPool.UpdateNewElement (Xamarin.Forms.VisualElement newElement) [0x00000] in <filename unknown>:0 at Xamarin.Forms.Platform.iOS.VisualElementPackager.SetElement (Xamarin.Forms.VisualElement oldElement, Xamarin.Forms.VisualElement newElement) [0x00000] in <filename unknown>:0 at Xamarin.Forms.Platform.iOS.VisualElementPackager.OnRendererElementChanged (System.Object sender, Xamarin.Forms.Platform.iOS.VisualElementChangedEventArgs args) [0x00000] in <filename unknown>:0 at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[Xamarin.Forms.VisualElement].OnElementChanged (Xamarin.Forms.Platform.iOS.ElementChangedEventArgs`1 e) [0x00000] in <filename unknown>:0 at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[Xamarin.Forms.VisualElement].SetElement (Xamarin.Forms.VisualElement element) [0x00000] in <filename unknown>:0 at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[Xamarin.Forms.VisualElement].Xamarin.Forms.Platform.iOS.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00000] in <filename unknown>:0 at Xamarin.Forms.Platform.iOS.ViewCellRenderer+ViewTableCell.UpdateCell (Xamarin.Forms.ViewCell cell) [0x00000] in <filename unknown>:0 at Xamarin.Forms.Platform.iOS.ViewCellRenderer+ViewTableCell.set_ViewCell (Xamarin.Forms.ViewCell value) [0x00000] in <filename unknown>:0 at Xamarin.Forms.Platform.iOS.ViewCellRenderer.GetCell (Xamarin.Forms.Cell item, UIKit.UITableViewCell reusableCell, UIKit.UITableView tv) [0x00000] in <filename unknown>:0 at Xamarin.Forms.Platform.iOS.CellTableViewCell.GetNativeCell (UIKit.UITableView tableView, Xamarin.Forms.Cell cell) [0x00000] in <filename unknown>:0 at Xamarin.Forms.Platform.iOS.ListViewRenderer+ListViewDataSource.GetCell (UIKit.UITableView tableView, Foundation.NSIndexPath indexPath) [0x00000] in <filename unknown>:0 at at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr) at UIKit.UIApplication.Main (System.String[] args, IntPtr principal, IntPtr delegate) [0x00005] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:62 at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:46 at BarberGuru.iOS.Application.Main (System.String[] args) [0x00008] in /Users/phazlett/Documents/workspace/BarberGuru/Xamarin/BarberGuru.iOS/Main.cs:17

    Saturday, February 7, 2015 10:40 AM