xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.64k stars 1.88k forks source link

iOS ListView ContextAction System.NullReferenceException: Object reference not set to an instance of an object #14292

Open filipleifer opened 3 years ago

filipleifer commented 3 years ago

Description

Very similar to https://github.com/xamarin/Xamarin.Forms/issues/11943

System.NullReferenceException: Object reference not set to an instance of an object at Xamarin.Forms.Platform.iOS.ContextActionsCell.ReloadRow () [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.iOS\ContextActionCell.cs:514

Steps to Reproduce

  1. Create ListView with caching strategy RecycleElementAndDataTemplate. Fill some data (50 records or more)
  2. Register ItemBindingContextChanged event and call ContextActions.Clear() for each item template
  3. Scroll down to end of ListView and load more 50 (or more) items

Expected Behavior

App will not crash and ListView items and context menu is correctly displayed.

Actual Behavior

App will crash on iOS when call ContextActions.Clear():

System.NullReferenceException: Object reference not set to an instance of an object at Xamarin.Forms.Platform.iOS.ContextActionsCell.ReloadRow () [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.iOS\ContextActionCell.cs:514

Full Exception:

exception.txt

Basic Information

Environment

Show/Hide Visual Studio info ``` ```

Workaround

Can be workarounded by: ` if(ContextActions.Any()) { ContextActions.Clear(); }

`

jsuarezruiz commented 3 years ago
System.NullReferenceException: Object reference not set to an instance of an object

  at Xamarin.Forms.Platform.iOS.ContextActionsCell.ReloadRow () [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.iOS\ContextActionCell.cs:514
  at Xamarin.Forms.Platform.iOS.ContextActionsCell.OnContextItemsChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00044] in D:\a\1\s\Xamarin.Forms.Platform.iOS\ContextActionCell.cs:497
  at at (wrapper delegate-invoke) <Module>.invoke_void_object_NotifyCollectionChangedEventArgs(object,System.Collections.Specialized.NotifyCollectionChangedEventArgs)
  at System.Collections.ObjectModel.ObservableCollection`1[T].OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00018] in <11ade8ccf21d4e088feeebdfa82d9e3b>:0
  at System.Collections.ObjectModel.ObservableCollection`1[T].OnCollectionReset () [0x00000] in <11ade8ccf21d4e088feeebdfa82d9e3b>:0
  at System.Collections.ObjectModel.ObservableCollection`1[T].ClearItems () [0x00018] in <11ade8ccf21d4e088feeebdfa82d9e3b>:0
  at System.Collections.ObjectModel.Collection`1[T].Clear () [0x00014] in <d7378003255d47168c07c9b138461e80>:0
  at iDoklad.ViewModels.ContactsPageViewModel.<get_ItemBindingContextChangedCommand>b__18_0 (Xamarin.Forms.ViewCell vc) [0x0000d] in /Users/filipleifer/Repos/iDokladMobile/iDoklad/iDoklad.App/iDoklad.ViewModels/ContactsPageViewModel.cs:66
  at XamarinFormsSDK.CSW.Definition.Operation`1+<>c__DisplayClass0_0[T].<.ctor>b__0 (System.Object p) [0x00000] in <5c694982d2fd49399aef9d25c4b91a79>:0
  at XamarinFormsSDK.CSW.Definition.Operation.Execute (System.Object parameter) [0x0001b] in C:\agent1\_work\1036\s\XamarinFormsSDK.CSW.Definition\Operation.cs:72
  at XamarinFormsSDK.CSW.Components.ViewCells.BindableViewCell+<>c__DisplayClass14_0.<BindableViewCell_BindingContextChanged>g__ExecuteBindingContextChangedCommand|0 () [0x00000] in C:\agent1\_work\1036\s\XamarinFormsSDK.CSW.Components\ViewCells\BindableViewCell.cs:74
  at XamarinFormsSDK.CSW.Components.ViewCells.BindableViewCell.BindableViewCell_BindingContextChanged (System.Object sender, System.EventArgs e) [0x00045] in C:\agent1\_work\1036\s\XamarinFormsSDK.CSW.Components\ViewCells\BindableViewCell.cs:92
  at Xamarin.Forms.BindableObject.OnBindingContextChanged () [0x00000] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:254
  at Xamarin.Forms.Element.OnBindingContextChanged () [0x00053] in D:\a\1\s\Xamarin.Forms.Core\Element.cs:319
  at Xamarin.Forms.Cell.OnBindingContextChanged () [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Cells\Cell.cs:156
  at Xamarin.Forms.BindableObject.BindingContextPropertyChanged (Xamarin.Forms.BindableObject bindable, System.Object oldvalue, System.Object newvalue) [0x0000f] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:550
  at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindableObject+BindablePropertyContext context, System.Object value, System.Boolean currentlyApplying, Xamarin.Forms.Internals.SetValueFlags attributes, System.Boolean silent) [0x00120] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:512
  at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes) [0x00173] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:446
  at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value, System.Boolean fromStyle, System.Boolean checkAccess) [0x0004d] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:374
  at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:349
  at Xamarin.Forms.BindableObject.set_BindingContext (System.Object value) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:31
  at Xamarin.Forms.Internals.TemplatedItemsList`2[TView,TItem].UpdateContent (TItem content, System.Int32 index, System.Object item) [0x00000] in <82bf00d73ba84d498079d53808841321>:0
  at Xamarin.Forms.Internals.TemplatedItemsList`2[TView,TItem].UpdateContent (TItem content, System.Int32 index) [0x0000d] in <82bf00d73ba84d498079d53808841321>:0
  at Xamarin.Forms.Internals.TemplatedItemsList`2[TView,TItem].Xamarin.Forms.ITemplatedItemsList<TItem>.UpdateContent (TItem content, System.Int32 index) [0x00000] in <82bf00d73ba84d498079d53808841321>:0
  at Xamarin.Forms.Platform.iOS.ListViewRenderer+ListViewDataSource.GetCell (UIKit.UITableView tableView, Foundation.NSIndexPath indexPath) [0x000af] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\ListViewRenderer.cs:1110
  at 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 /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:86
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0000e] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:65