Bug 59813 - "NullReferenceException" in "Xamarin.Forms.Platform.iOS.Renderers.LabelRenderer.cs" within "UpdateText()" & "UpdateTextColor()"
Summary: "NullReferenceException" in "Xamarin.Forms.Platform.iOS.Renderers.LabelRender...
Status: REOPENED
Alias: None
Product: Forms
Classification: Xamarin
Component: iOS (show other bugs)
Version: 2.4.0
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-09-28 10:56 UTC by Mathias Hartner
Modified: 2017-12-04 16:51 UTC (History)
27 users (show)

See Also:
Tags: nre, updatetext, ac fr
Is this bug a regression?: Yes
Last known good build: 2.3.5.239-pre3


Attachments
An updated test project which constantly produces the exception within "UpdateText()" (1.72 MB, application/x-zip-compressed)
2017-11-15 14:28 UTC, Mathias Hartner
Details

Description Mathias Hartner 2017-09-28 10:56:00 UTC
Hey guys,

I have yet another bug for you...Here's the stack trace for "UpdateTextColor()":

2017-09-27 16:41:32.255 [1] [Error] An unhandled exception occurred and was caught by global exception handler CurrentDomainOnUnhandledException. System.NullReferenceException: Object reference not set to an instance of an object
  at Xamarin.Forms.Platform.iOS.LabelRenderer.UpdateTextColor () [0x00026] in C:\BuildAgent\work\ca3766cfc22354a1\Xamarin.Forms.Platform.iOS\Renderers\LabelRenderer.cs:319 
  at Xamarin.Forms.Platform.iOS.LabelRenderer.OnElementPropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs e) [0x0005b] in C:\BuildAgent\work\ca3766cfc22354a1\Xamarin.Forms.Platform.iOS\Renderers\LabelRenderer.cs:146 
  at (wrapper delegate-invoke) <Module>:invoke_void_object_PropertyChangedEventArgs (object,System.ComponentModel.PropertyChangedEventArgs)
  at Xamarin.Forms.BindableObject.OnPropertyChanged (System.String propertyName) [0x0000a] in C:\BuildAgent\work\ca3766cfc22354a1\Xamarin.Forms.Core\BindableObject.cs:137 
  at Xamarin.Forms.Element.OnPropertyChanged (System.String propertyName) [0x00000] in C:\BuildAgent\work\ca3766cfc22354a1\Xamarin.Forms.Core\Element.cs:388 
  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) [0x000f4] in C:\BuildAgent\work\ca3766cfc22354a1\Xamarin.Forms.Core\BindableObject.cs:593 
  at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes) [0x0015b] in C:\BuildAgent\work\ca3766cfc22354a1\Xamarin.Forms.Core\BindableObject.cs:390 
  at Xamarin.Forms.BindingExpression.ApplyCore (System.Object sourceObject, Xamarin.Forms.BindableObject target, Xamarin.Forms.BindableProperty property, System.Boolean fromTarget) [0x001f9] in C:\BuildAgent\work\ca3766cfc22354a1\Xamarin.Forms.Core\BindingExpression.cs:174 
  at Xamarin.Forms.BindingExpression.Apply (System.Boolean fromTarget) [0x0003e] in C:\BuildAgent\work\ca3766cfc22354a1\Xamarin.Forms.Core\BindingExpression.cs:56 
  at Xamarin.Forms.BindingExpression+BindingExpressionPart.<PropertyChanged>b__47_0 () [0x00000] in C:\BuildAgent\work\ca3766cfc22354a1\Xamarin.Forms.Core\BindingExpression.cs:551 
  at Foundation.NSAsyncActionDispatcher.Apply () [0x00000] in /Users/builder/data/lanes/5024/152b654a/source/xamarin-macios/src/Foundation/NSAction.cs:163 
  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/data/lanes/5024/152b654a/source/xamarin-macios/src/UIKit/UIApplication.cs:79 
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Users/builder/data/lanes/5024/152b654a/source/xamarin-macios/src/UIKit/UIApplication.cs:63 
  at XXX.Mobile.iOS.Application.Main (System.String[] args) [0x0001b] in D:\Sources\XXXCollection\Branches\MobileBranch\Mobile\XXX.Mobile.iOS\Main.cs:21

Stacktrace for "UpdateText()":

2017-09-27 17:03:58.016 [1] [Error] An unhandled exception occurred and was caught by global exception handler CurrentDomainOnUnhandledException. System.NullReferenceException: Object reference not set to an instance of an object
  at Xamarin.Forms.Platform.iOS.LabelRenderer.UpdateText () [0x0006a] in C:\BuildAgent\work\ca3766cfc22354a1\Xamarin.Forms.Platform.iOS\Renderers\LabelRenderer.cs:285 
  at Xamarin.Forms.Platform.iOS.LabelRenderer.OnElementPropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs e) [0x00097] in C:\BuildAgent\work\ca3766cfc22354a1\Xamarin.Forms.Platform.iOS\Renderers\LabelRenderer.cs:150 
  at (wrapper delegate-invoke) <Module>:invoke_void_object_PropertyChangedEventArgs (object,System.ComponentModel.PropertyChangedEventArgs)
  at Xamarin.Forms.BindableObject.OnPropertyChanged (System.String propertyName) [0x0000a] in C:\BuildAgent\work\ca3766cfc22354a1\Xamarin.Forms.Core\BindableObject.cs:137 
  at Xamarin.Forms.Element.OnPropertyChanged (System.String propertyName) [0x00000] in C:\BuildAgent\work\ca3766cfc22354a1\Xamarin.Forms.Core\Element.cs:388 
  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) [0x000f4] in C:\BuildAgent\work\ca3766cfc22354a1\Xamarin.Forms.Core\BindableObject.cs:593 
  at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes) [0x0015b] in C:\BuildAgent\work\ca3766cfc22354a1\Xamarin.Forms.Core\BindableObject.cs:390 
  at Xamarin.Forms.BindingExpression.ApplyCore (System.Object sourceObject, Xamarin.Forms.BindableObject target, Xamarin.Forms.BindableProperty property, System.Boolean fromTarget) [0x001f9] in C:\BuildAgent\work\ca3766cfc22354a1\Xamarin.Forms.Core\BindingExpression.cs:174 
  at Xamarin.Forms.BindingExpression.Apply (System.Boolean fromTarget) [0x0003e] in C:\BuildAgent\work\ca3766cfc22354a1\Xamarin.Forms.Core\BindingExpression.cs:56 
  at Xamarin.Forms.BindingExpression+BindingExpressionPart.<PropertyChanged>b__47_0 () [0x00000] in C:\BuildAgent\work\ca3766cfc22354a1\Xamarin.Forms.Core\BindingExpression.cs:551 
  at Foundation.NSAsyncActionDispatcher.Apply () [0x00000] in /Users/builder/data/lanes/5024/152b654a/source/xamarin-macios/src/Foundation/NSAction.cs:163 
  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/data/lanes/5024/152b654a/source/xamarin-macios/src/UIKit/UIApplication.cs:79 
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Users/builder/data/lanes/5024/152b654a/source/xamarin-macios/src/UIKit/UIApplication.cs:63 
  at XXX.Mobile.iOS.Application.Main (System.String[] args) [0x0001b] in D:\Sources\XXXCollection\Branches\MobileBranch\Mobile\XXX.Mobile.iOS\Main.cs:21

It happens within a list view which gets cyclically updated every second if it is visible. 
The list view only contains labels with different colors and is part of a child page within a carousel page.
It happens when swiping into the child page containing the list view (The list view has been updated with new items shortly before).

With Xamarin.Forms 2.3.5.239-pre3 everything is fine. Due to another bug I had to wait for 2.4.0.269-pre2 but that version had another bug and I had to wait for 2.4.0.275-pre3...But now I realized that all those new versions have this bug here that also prevent me from using them...Even with the newest version 2.4.0.280 the problem still exists!

It seems to be a never-ending story!!!

I hope the provided information is enough for you because I don't know what else I could provide you...

Kind regards,

Mathias Hartner
Comment 1 Paul DiPietro [MSFT] 2017-09-28 16:07:01 UTC
Can you give us a reproduction so we have the exact code you're using?
Comment 2 krispenner 2017-10-03 03:27:06 UTC
Xamarin.Forms 2.4.0.282
I also got the same error, unfortunately I have no idea which label is throwing this but it is within a ViewCell created from a data template for the list items in a list view after the ItemSource property's bound list as been cleared and the same number of items re-added.  Hope that can help a little bit!

Based on GitHub line 285 of iOS LabelRenderer is:
Control.Text = (string)values[1];  // is Control or values somehow null?

https://github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.Platform.iOS/Renderers/LabelRenderer.cs

Stack Trace:
  at Xamarin.Forms.Platform.iOS.LabelRenderer.UpdateText () [0x0006a] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.iOS\Renderers\LabelRenderer.cs:285 
  at Xamarin.Forms.Platform.iOS.LabelRenderer.OnElementPropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs e) [0x00097] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.iOS\Renderers\LabelRenderer.cs:150 
  at (wrapper delegate-invoke) <Module>:invoke_void_object_PropertyChangedEventArgs (object,System.ComponentModel.PropertyChangedEventArgs)
  at Xamarin.Forms.BindableObject.OnPropertyChanged (System.String propertyName) [0x0000a] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\BindableObject.cs:137 
  at Xamarin.Forms.Element.OnPropertyChanged (System.String propertyName) [0x00000] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\Element.cs:388 
  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) [0x000f4] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\BindableObject.cs:593 
  at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes) [0x0015b] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\BindableObject.cs:390 
  at Xamarin.Forms.BindingExpression.ApplyCore (System.Object sourceObject, Xamarin.Forms.BindableObject target, Xamarin.Forms.BindableProperty property, System.Boolean fromTarget) [0x001f9] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\BindingExpression.cs:174 
  at Xamarin.Forms.BindingExpression.Apply (System.Object sourceObject, Xamarin.Forms.BindableObject target, Xamarin.Forms.BindableProperty property) [0x0006b] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\BindingExpression.cs:77 
  at Xamarin.Forms.Binding.Apply (System.Object newContext, Xamarin.Forms.BindableObject bindObj, Xamarin.Forms.BindableProperty targetProperty) [0x00042] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\Binding.cs:126 
  at Xamarin.Forms.BindableObject.ApplyBindings (System.Boolean skipBindingContext) [0x0003b] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\BindableObject.cs:421 
  at Xamarin.Forms.BindableObject.ApplyBindings () [0x00000] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\BindableObject.cs:125 
  at Xamarin.Forms.BindableObject.SetInheritedBindingContext (Xamarin.Forms.BindableObject bindable, System.Object value) [0x0005a] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\BindableObject.cs:119 
  at Xamarin.Forms.Element.SetChildInheritedBindingContext (Xamarin.Forms.Element child, System.Object context) [0x00000] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\Element.cs:498 
  at Xamarin.Forms.Element.OnBindingContextChanged () [0x00021] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\Element.cs:341 
  at Xamarin.Forms.View.OnBindingContextChanged () [0x00042] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\View.cs:99 
  at Xamarin.Forms.BindableObject.SetInheritedBindingContext (Xamarin.Forms.BindableObject bindable, System.Object value) [0x00060] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\BindableObject.cs:120 
  at Xamarin.Forms.Element.SetChildInheritedBindingContext (Xamarin.Forms.Element child, System.Object context) [0x00000] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\Element.cs:498 
  at Xamarin.Forms.Element.OnBindingContextChanged () [0x00021] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\Element.cs:341 
  at Xamarin.Forms.Cell.OnBindingContextChanged () [0x00000] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\Cells\Cell.cs:114 
  at Xamarin.Forms.BindableObject.BindingContextPropertyChanged (Xamarin.Forms.BindableObject bindable, System.Object oldvalue, System.Object newvalue) [0x0000e] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\BindableObject.cs:441 
  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) [0x00108] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\BindableObject.cs:596 
  at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes) [0x0015b] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\BindableObject.cs:390 
  at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value, System.Boolean fromStyle, System.Boolean checkAccess) [0x0005f] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\BindableObject.cs:543 
  at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value) [0x00000] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\BindableObject.cs:83 
  at Xamarin.Forms.BindableObject.set_BindingContext (System.Object value) [0x00000] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\BindableObject.cs:24 
  at Xamarin.Forms.Internals.TemplatedItemsList`2+<UnhookItem>d__154[TView,TItem].MoveNext () [0x000b0] in <1982f4f36e0b4e118327ea411be26e7b>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.0.0.0/src/mono/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:151 
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_0 (System.Object state) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.0.0.0/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1018 
  at UIKit.UIKitSynchronizationContext+<Post>c__AnonStorey0.<>m__0 () [0x00000] in /Users/builder/data/lanes/5024/152b654a/source/xamarin-macios/src/UIKit/UIKitSynchronizationContext.cs:24 
  at Foundation.NSAsyncActionDispatcher.Apply () [0x00000] in /Users/builder/data/lanes/5024/152b654a/source/xamarin-macios/src/Foundation/NSAction.cs:163 
  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/data/lanes/5024/152b654a/source/xamarin-macios/src/UIKit/UIApplication.cs:79 
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Users/builder/data/lanes/5024/152b654a/source/xamarin-macios/src/UIKit/UIApplication.cs:63
Comment 3 krispenner 2017-10-03 04:15:45 UTC
I can confirm that the property Control is NULL in LabelRenderer on line 285 of the UpdateText() method.

Control.Text = (string)values[1];  // Control is null

https://github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.Platform.iOS/Renderers/LabelRenderer.cs

I confirmed this by overriding the LabelRenderer with a custom render and in the OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) method when the "Text" property has changed, the Control property is NULL and calling the base method then throws a NullReferenceException.

It may be some sort of a race condition, as it happens 80% of the time, the other 20% things work.

I don't think this happened prior to me adding a grouping to the list item source, and on the ListView specifying both the GroupHeaderTemplate for the grouping in the list and the GroupShortNameBinding for the jump list.
Comment 4 krispenner 2017-10-03 04:17:59 UTC
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
The work around for  if anyone experiencing this, is unfortunately to disable item recycling, although my lists suck at scrolling now and they are huge.
CachingStrategy="RecycleElement" causes this issue.
CachingStrategy="RetainElement" never has an issue.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Comment 5 mailcannon 2017-10-03 09:53:34 UTC
take a look at https://bugzilla.xamarin.com/show_bug.cgi?id=59716
Comment 6 matteo 2017-10-03 13:15:16 UTC
Even with RetainElement I have the same problem...
Comment 7 mailcannon 2017-10-04 04:47:05 UTC
I have the problem with lists and labels only with RetainElement and  RecycleElement solves it for me. So the workarround is not universal. Actual thing is never solves even if labels are not in lists. And not only labels. It's something with PropertyChanged notifications.
To make your lists a little bit stable you need to mix and play with: CachingStrategy, HasUnevenRows and ViewCell template, from my testing
Comment 8 krispenner 2017-10-04 06:57:37 UTC
Yes, I agree, I found another issue related to this when refreshing the items in one of my ListViews I get the below stack trace.  You can see it has to do with 
Xamarin.Forms.Platform.iOS.ListViewRenderer+UnevenListViewDataSource.CalculateHeightForCell

which based on you mentioning HasUnevenRows, I realized all these errors in ListView and Label renderers all started immediately after I set HasUnevenRows to true on all my ListViews so I could have a smaller GroupHeader row.

I have now switched HasUnevenRows back to false (small price to pay with larger group header rows than I wanted) and I have also re-enabled RecycleElement on all my ListViews.  Every ListView now has no issues and they scroll very fast due to (RecycleElement).

Can anyone confirm with setting HasUnevenRows to false if this issue goes away for them?



System.NullReferenceException: Object reference not set to an instance of an object
  at Xamarin.Forms.Platform.iOS.EventTracker.LoadRecognizers () [0x0005d] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.iOS\EventTracker.cs:347 
  at Xamarin.Forms.Platform.iOS.EventTracker.OnElementChanged (System.Object sender, Xamarin.Forms.Platform.iOS.VisualElementChangedEventArgs e) [0x0004e] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.iOS\EventTracker.cs:413 
  at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[TElement].OnElementChanged (Xamarin.Forms.Platform.iOS.ElementChangedEventArgs`1[TElement] e) [0x0002c] in <c95050a8f6d640e8927ac3f95b517dff>:0 
  at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[TElement].SetElement (TElement element) [0x00118] in <c95050a8f6d640e8927ac3f95b517dff>:0 
  at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[TElement].Xamarin.Forms.Platform.iOS.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00000] in <c95050a8f6d640e8927ac3f95b517dff>:0 
  at Xamarin.Forms.Platform.iOS.RendererPool.UpdateRenderers (Xamarin.Forms.Element newElement) [0x0008c] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.iOS\RendererPool.cs:152 
  at Xamarin.Forms.Platform.iOS.RendererPool.UpdateNewElement (Xamarin.Forms.VisualElement newElement) [0x00080] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.iOS\RendererPool.cs:78 
  at Xamarin.Forms.Platform.iOS.VisualElementPackager.SetElement (Xamarin.Forms.VisualElement oldElement, Xamarin.Forms.VisualElement newElement) [0x00050] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:151 
  at Xamarin.Forms.Platform.iOS.VisualElementPackager.OnRendererElementChanged (System.Object sender, Xamarin.Forms.Platform.iOS.VisualElementChangedEventArgs args) [0x0000f] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:134 
  at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[TElement].OnElementChanged (Xamarin.Forms.Platform.iOS.ElementChangedEventArgs`1[TElement] e) [0x0002c] in <c95050a8f6d640e8927ac3f95b517dff>:0 
  at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[TElement].SetElement (TElement element) [0x00118] in <c95050a8f6d640e8927ac3f95b517dff>:0 
  at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[TElement].Xamarin.Forms.Platform.iOS.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00000] in <c95050a8f6d640e8927ac3f95b517dff>:0 
  at Xamarin.Forms.Platform.iOS.ListViewRenderer+UnevenListViewDataSource.CalculateHeightForCell (UIKit.UITableView tableView, Xamarin.Forms.Cell cell) [0x00035] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.iOS\Renderers\ListViewRenderer.cs:727 
  at Xamarin.Forms.Platform.iOS.ListViewRenderer+UnevenListViewDataSource.GetEstimatedRowHeight (UIKit.UITableView table) [0x0005d] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.iOS\Renderers\ListViewRenderer.cs:671 
  at Xamarin.Forms.Platform.iOS.ListViewRenderer.UpdateEstimatedRowHeight () [0x0005f] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.iOS\Renderers\ListViewRenderer.cs:394 
  at Xamarin.Forms.Platform.iOS.ListViewRenderer.UpdateItems (System.Collections.Specialized.NotifyCollectionChangedEventArgs e, System.Int32 section, System.Boolean resetWhenGrouped) [0x000b9] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.iOS\Renderers\ListViewRenderer.cs:515 
  at Xamarin.Forms.Platform.iOS.ListViewRenderer.OnCollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00000] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.iOS\Renderers\ListViewRenderer.cs:298 
  at Xamarin.Forms.Internals.TemplatedItemsList`2[TView,TItem].OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x0000a] in <1982f4f36e0b4e118327ea411be26e7b>:0 
  at Xamarin.Forms.Internals.TemplatedItemsList`2[TView,TItem].OnCollectionChangedGrouped (System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x000e3] in <1982f4f36e0b4e118327ea411be26e7b>:0 
  at Xamarin.Forms.Internals.TemplatedItemsList`2[TView,TItem].OnProxyCollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e, System.Boolean fixWindows) [0x00008] in <1982f4f36e0b4e118327ea411be26e7b>:0 
  at Xamarin.Forms.Internals.TemplatedItemsList`2[TView,TItem].OnProxyCollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00000] in <1982f4f36e0b4e118327ea411be26e7b>:0 
  at Xamarin.Forms.ListProxy.OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x0000a] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\ListProxy.cs:233 
  at Xamarin.Forms.ListProxy+<>c__DisplayClass33_0.<OnCollectionChanged>b__0 () [0x00018] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\ListProxy.cs:206 
  at Xamarin.Forms.ListProxy.OnCollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x000a0] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\ListProxy.cs:225 
  at Xamarin.Forms.ListProxy+WeakNotifyProxy.OnCollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00031] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\ListProxy.cs:394
Comment 9 matteo 2017-10-04 08:24:46 UTC
The problem occurs even with HasUnevenRows set to false.

The main problem is only on the Label component.
Each times, at the third 'pull to refresh' gesture, the app crash

If instead to bind the Text property I set a fixed value (for example 'test') then the app work without crash, even after the third 'pull to refresh action'
Comment 10 matteo 2017-10-04 08:36:16 UTC
I roll back to xf 2.3.5.239-pre6
Now it works
Comment 11 Mathias Hartner 2017-10-12 10:53:06 UTC
@Xamarin-Team: Is there any progress here? Is the provided information enough for you guys ti figure it out? Can you please tell us when to expect this issue to be resolved?
Comment 12 Shane 2017-10-17 04:22:14 UTC
@matteo thanks for the insight with the bindings. Changing over to just setting things manually instead of using bindings worked well for now
Comment 13 flywhc 2017-10-18 08:51:57 UTC
I saw same exactly problem when using Label in Forms.ListView, when quickly replacing binding data with a List of items in a multithreading program, about 20% chance to see this exception. The exception occurred NOT immediately after my replacing function and NOT in my application thread.

This is the 2nd critical bug I found in Xamarin Forms 2.4.
Comment 14 Doug Johns 2017-10-18 18:30:48 UTC
I am experiencing this issue as well. 

I have a ListView contained in a Grid, with HasUnevenRows and IsGroupingEnabled. Both the GroupHeaderTemplate and the ItemTemplate have Grids with multiple Labels contained inside. All static text is being pulled from a localization resource, and all dynamic text is being bound from the ViewModel.

Using Xamarin.Forms 2.3.4.270, all works as expected. 

When I update to 2.4.0.282, there's an inconsistent error being thrown with the stack trace in Comment 2. This mainly occurs after the 3rd or 4th update from the ViewModel, but not at a constant rate.

Also, when I'm on 2.4.0.282, I'm getting another error from iOS itself. This is what HockeyApp reports as the error message in this scenario: 
"Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of sections. The number of sections contained in the table view after the update (2) must be equal to the number of sections contained in the table view before the update (1), plus or minus the number of sections inserted or deleted (0 inserted, 0 deleted)."
This seems to occur less frequently than the above, about 10% of the time after an update from the ViewModel.

I've attempted to create a small repo project, but am unable to reproduce either of these issues this way.
Comment 15 Mathias Hartner 2017-10-19 15:10:14 UTC
I'm setting this to assgined in the hope you guys can figure it out.
As you can see, here are a lot of folks who struggle with the same problems and I think there should be enough information for you to point you in the right direction.
Comment 16 Paul DiPietro [MSFT] 2017-10-19 15:33:16 UTC
Please don't set bugs to assigned, as we set that status on our end as part of internal tracking and it could get lost in the shuffle otherwise. We still would very much prefer getting a reproduction to see precisely the code being used. Lease let me stress that even if it reproduces only a small portion of the time, like 10 or 20 percent, it's better than nothing at all.
Comment 17 Mathias Hartner 2017-10-19 15:38:23 UTC
OK, I'll try to reproduce it and hope to provide you a demonstrating project until tomorrow.
Comment 18 Mathias Hartner 2017-10-20 12:55:40 UTC
Created attachment 25381 [details]
A test project which constantly produces the exception within "UpdateText()"

So finally I have a test project which always produces a NRE within "UpdateText()". Please keep it private because it contains a lot of business code.

Just set the iOS project as startup project (if it isn't already) and start the app on a device or on the simulator. Don't worry it will take some time until you see the "Browse" page. Head over to the tab "Function Dialog" on the lower right and wait until the breakpoint is hit. If the breakpoint shouldn't be set, set it in "FunctionDialogViewModel" at line 260.

I removed all NuGet packages and bin/obj folders to not exceed the file size limit.

Please make at least the test project private, I don't have the rights to do so.
Comment 19 Paul DiPietro [MSFT] 2017-10-23 03:06:06 UTC
Thank you for the reproduction. It is a bit hefty but certainly better than nothing to work with. I will set this as confirmed until it can be further investigated.
Comment 20 cjw1115@hotmail.com 2017-10-24 08:31:50 UTC
it's a bug about ListViewRenderer.
When I install Xamarin.Forms2.3.4,everything is ok.But when I install Xamarin.Fomrs2.4.0,the app will be crash when the itemsource changed frequently.
And I have made a git diff between 2.3.4 and 2.4.0 version about ListViewRenderer.cs,I found that the renderer is almost refactor.
Comment 21 Romulo 2017-10-24 15:57:38 UTC
Hey Guys, chiming in from over here:

https://forums.xamarin.com/discussion/105476/listview-nullreferenceexception-when-reseting-updating-itemsource

Setting HasUnevenRows to false and setting RowHeight manually works around this bug.
Comment 22 Samantha Houts [MSFT] 2017-10-24 18:42:55 UTC
https://github.com/xamarin/Xamarin.Forms/pull/1216
Comment 23 Chris King 2017-10-24 20:45:45 UTC
Actually, let's go with this fix: https://github.com/xamarin/Xamarin.Forms/pull/1226
Comment 24 yamachu 2017-11-01 17:52:31 UTC
https://bugzilla.xamarin.com/show_bug.cgi?id=59813#c23
I built Xamarin.Forms with this PR and https://github.com/xamarin/Xamarin.Forms/pull/1244 
Then I confirmed that my app(https://github.com/yamachu/TonpeiFes2017) would crash or not.
My app didn't crash!

This issue seems to be solved.
Comment 25 Samantha Houts [MSFT] 2017-11-03 21:15:26 UTC
Should be fixed in 2.4.0 SR4. Thank you!
Comment 26 Mathias Hartner 2017-11-07 10:37:54 UTC
Even with version 2.4.0.38779 I still get the same exception like I stated in my last comment 18. Now I don't get any exception within "UpdateText()" but I still get a NRE in code line 319 within "UpdateTextColor()". Just run my sample project with version 2.4.0.38779 and you can see that.

So this issue has not yet been resolved!
Comment 27 yamachu 2017-11-07 10:51:39 UTC
Did you try Xamarin.Forms sr-4?
Xamarin.Forms 2.4.0.38779 is sr-3.

Currently we cannot try sr-4 via nuget.org...

So download sr-4 from here
https://github.com/xamarin/Xamarin.Forms/releases/tag/release-2.4.0-sr4
Comment 28 TRO Solo 2017-11-07 11:01:19 UTC
To clarify: Service Release 4 (SR-4) is version 2.4.0.56808 and can be downloaded manually via the link @yamachu provided.
Comment 29 Mathias Hartner 2017-11-07 11:15:02 UTC
Yep...My bad...

I thought SR4 is version 2.4.0.38779 but actually it is 2.4.0.56808.
So thanks for the download link and the clarification guys!

I tested it and the bug seems also to be fixed for me.

THX all!
Comment 30 ThumbGen 2017-11-07 11:16:10 UTC
Will the SR4 be published on nuget.org soon?

Thx
/R
Comment 31 TRO Solo 2017-11-09 10:57:04 UTC
Regarding the UpdateTextColor() bug and stack trace mentioned in the first comment: We encounter this exception occasionally even with SR-4. Based on customer feedback and crash report analyzing, this might be due to the usage of DynamicResources for the TextColor property of the Label. We support theme switching at runtime and our Labels' TextColor properties are set to a DynamicResource located within the ResourceDictionary defined within the App.xaml which we update with pre-defined values.

Some newly received crash reports indicate that the user might have used this feature just before the System.NullReferenceException gets thrown by the Xamarin.Forms.Platform.iOS.LabelRenderer.UpdateTextColor method.
Comment 32 ThumbGen 2017-11-13 11:29:12 UTC
I got the error again, using Xamarin.Forms 2.4.0.74863

I set TextColor for a Label like:

TextColor="{Binding IsSelected, Converter={StaticResource SelectedToColorConverter}}"

where the SelectedToColorConverter simply returns a Color object.

Stack trace:

at Xamarin.Forms.Platform.iOS.LabelRenderer.UpdateTextColor () <0x1014734c0 + 0x000f4> in <eb211aa32ac8429489411f4d642db9c2#8e1c0bfe1aaff8acf65b2474903c6737>:0 
  at Xamarin.Forms.Platform.iOS.LabelRenderer.OnElementPropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs e) <0x101472c60 + 0x000db> in <eb211aa32ac8429489411f4d642db9c2#8e1c0bfe1aaff8acf65b2474903c6737>:0 
  at (wrapper delegate-invoke) <Module>:invoke_void_object_PropertyChangedEventArgs (object,System.ComponentModel.PropertyChangedEventArgs)
  at Xamarin.Forms.BindableObject.OnPropertyChanged (System.String propertyName) <0x1012e5750 + 0x0007f> in <6f4d3098293c4695a30698c64c576a90#8e1c0bfe1aaff8acf65b2474903c6737>:0 
  at Xamarin.Forms.Element.OnPropertyChanged (System.String propertyName) <0x101356580 + 0x00023> in <6f4d3098293c4695a30698c64c576a90#8e1c0bfe1aaff8acf65b2474903c6737>:0 
  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) <0x1012e8040 + 0x00247> in <6f4d3098293c4695a30698c64c576a90#8e1c0bfe1aaff8acf65b2474903c6737>:0 
  at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes) <0x1012e6f40 + 0x00517> in <6f4d3098293c4695a30698c64c576a90#8e1c0bfe1aaff8acf65b2474903c6737>:0 
  at Xamarin.Forms.BindingExpression.ApplyCore (System.Object sourceObject, Xamarin.Forms.BindableObject target, Xamarin.Forms.BindableProperty property, System.Boolean fromTarget) <0x1012edbb0 + 0x005bf> in <6f4d3098293c4695a30698c64c576a90#8e1c0bfe1aaff8acf65b2474903c6737>:0 
  at Xamarin.Forms.BindingExpression.Apply (System.Boolean fromTarget) <0x1012ed840 + 0x0008f> in <6f4d3098293c4695a30698c64c576a90#8e1c0bfe1aaff8acf65b2474903c6737>:0 
  at Xamarin.Forms.BindingExpression+BindingExpressionPart.<PropertyChanged>b__47_0 () <0x1012f07c0 + 0x00023> in <6f4d3098293c4695a30698c64c576a90#8e1c0bfe1aaff8acf65b2474903c6737>:0 
  at Foundation.NSAsyncActionDispatcher.Apply () <0x101528c60 + 0x00023> in <f5f7bf9082f2423098c34fc985600d02#8e1c0bfe1aaff8acf65b2474903c6737>:0 
  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) <0x1015472d0 + 0x0002b> in <f5f7bf9082f2423098c34fc985600d02#8e1c0bfe1aaff8acf65b2474903c6737>:0 
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) <0x101547210 + 0x000ab> in <f5f7bf9082f2423098c34fc985600d02#8e1c0bfe1aaff8acf65b2474903c6737>:0 
  at PTMate.iOS.Application.Main (System.String[] args) <0x100aae840 + 0x00023> in <118ebb1c535e414c9c27ea53b2559240#8e1c0bfe1aaff8acf65b2474903c6737>:0
Comment 33 Luis 2017-11-14 09:08:50 UTC
We've got similar crashes on 2.4.0 SR5.

*** Terminating app due to uncaught exception 'System.NullReferenceException', reason: 'System.NullReferenceException: Object reference not set to an instance of an object'

Xamarin Exception Stack:
  at Xamarin.Forms.Platform.iOS.LabelRenderer.UpdateText () [0x0006a] in D:\agent\_work\1\s\Xamarin.Forms.Platform.iOS\Renderers\LabelRenderer.cs:285 
  at Xamarin.Forms.Platform.iOS.LabelRenderer.OnElementPropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs e) [0x00097] in D:\agent\_work\1\s\Xamarin.Forms.Platform.iOS\Renderers\LabelRenderer.cs:150 
  at (wrapper delegate-invoke) <Module>:invoke_void_object_PropertyChangedEventArgs (object,System.ComponentModel.PropertyChangedEventArgs)
  at Xamarin.Forms.BindableObject.OnPropertyChanged (System.String propertyName) [0x0000a] in D:\agent\_work\1\s\Xamarin.Forms.Core\BindableObject.cs:137 
  at Xamarin.Forms.Element.OnPropertyChanged (System.String propertyName) [0x00000] in D:\agent\_work\1\s\Xamarin.Forms.Core\Element.cs:388 
  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) [0x000f4] in D:\agent\_work\1\s\Xamarin.Forms.Core\BindableObject.cs:593 
  at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes) [0x0015b] in D:\agent\_work\1\s\Xamarin.Forms.Core\BindableObject.cs:390 
  at Xamarin.Forms.BindingExpression.ApplyCore (System.Object sourceObject, Xamarin.Forms.BindableObject target, Xamarin.Forms.BindableProperty property, System.Boolean fromTarget) [0x001f9] in D:\agent\_work\1\s\Xamarin.Forms.Core\BindingExpression.cs:174 
  at Xamarin.Forms.BindingExpression.Apply (System.Boolean fromTarget) [0x0003e] in D:\agent\_work\1\s\Xamarin.Forms.Core\BindingExpression.cs:56 
  at Xamarin.Forms.BindingExpression+BindingExpressionPart.<PropertyChanged>b__47_0 () [0x00000] in D:\agent\_work\1\s\Xamarin.Forms.Core\BindingExpression.cs:551 
  at Foundation.NSAsyncActionDispatcher.Apply () [0x00000] in /Users/builder/data/lanes/5024/152b654a/source/xamarin-macios/src/Foundation/NSAction.cs:163 
--- End of stack trace from previous location where exception was thrown ---
  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/data/lanes/5024/152b654a/source/xamarin-macios/src/UIKit/UIApplication.cs:79 
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Users/builder/data/lanes/5024/152b654a/source/xamarin-macios/src/UIKit/UIApplication.cs:63
Comment 34 Mathias Hartner 2017-11-15 14:28:32 UTC
Created attachment 25720 [details]
An updated test project which constantly produces the exception within "UpdateText()"

As I can see we are not the only ones who are still struggling with 2.4.0.56808.
But I took some time and adjusted my sample project to produce the same exception at the same location as in our production code.

Just set the iOS project as startup project (if it isn't already) and start the app on a device or on the simulator. Don't worry it will take some time until you see the "Browse" page. Head over to the tab "Function Dialog" on the lower right. Then tap on "Hour" (Funnily enough if you tap on "Minute" or "Second" and change the value, no NRE is raised). A new content page with an entry field on the top will appear. Change the default value and wait until the breakpoint is hit. If the breakpoint shouldn't be set, set it in "ParameterListViewItem" at line 57. The exception will occur after the fourth time the breakpoint has been hit.
It has definitely to do with "HasUnevenRows" of the list view.
If it is set to "false", no NRE is raised. Unfortunately we need it to be set to "true".

See my comments within method "AddFakeParameterViewModels()" & within the property changed handler of "ParameterListViewItem.cs".

Again, I removed all NuGet packages and bin/obj folders to not exceed the file size limit and please make the attachment private, same reasons as before!
Comment 35 Luis 2017-11-16 16:37:58 UTC
Still failing on 2.5.0.77107 for us (as probably expected, but had to give it a go).
Comment 36 Mathias Hartner 2017-11-20 17:47:23 UTC
Did my sample project help you guyz to narrow it down?
Any progress so far? Please give us a short info about the current state.
Thanks in advance.
Comment 37 Tejas 2017-11-26 20:28:50 UTC
I'm able to repro the issue with ListViews+HasUnevenRows=true, as reported by krispenner@hotmail.com above on XF 2.5.0.91635.

Unhandled Exception:
System.NullReferenceException: Object reference not set to an instance of an object
  at Xamarin.Forms.Platform.iOS.EventTracker.LoadRecognizers () [0x0005d] in D:\agent\_work\2\s\Xamarin.Forms.Platform.iOS\EventTracker.cs:373 
  at Xamarin.Forms.Platform.iOS.EventTracker.OnElementChanged (System.Object sender, Xamarin.Forms.Platform.iOS.VisualElementChangedEventArgs e) [0x0004e] in D:\agent\_work\2\s\Xamarin.Forms.Platform.iOS\EventTracker.cs:439 
  at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[TElement].OnElementChanged (Xamarin.Forms.Platform.iOS.ElementChangedEventArgs`1[TElement] e) [0x0002c] in <9a5948fff8254b13a3d593c76c73b9b1>:0 
  at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[TElement].SetElement (TElement element) [0x00118] in <9a5948fff8254b13a3d593c76c73b9b1>:0 
  at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[TElement].Xamarin.Forms.Platform.iOS.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualE
lement element) [0x00000] in <9a5948fff8254b13a3d593c76c73b9b1>:0 
  at Xamarin.Forms.Platform.iOS.RendererPool.UpdateRenderers (Xamarin.Forms.Element newElement) [0x0008c] in D:\agent\_work\2\s\Xamarin.Forms.Platform.iOS\RendererPool.cs:157 
  at Xamarin.Forms.Platform.iOS.RendererPool.UpdateNewElement (Xamarin.Forms.VisualElement newElement) [0x00080] in D:\agent\_work\2\s\Xamarin.Forms.Platform.iOS\RendererPool.cs:78 
  at Xamarin.Forms.Platform.iOS.VisualElementPackager.SetElement (Xamarin.Forms.VisualElement oldElement, Xamarin.Forms.VisualElement newElement) [0x00050] in D:\agent\_work\2\s\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:161 
  at Xamarin.Forms.Platform.iOS.VisualElementPackager.OnRendererElementChanged (System.Object sender, Xamarin.Forms.Platform.iOS.VisualElementChangedEventArgs args) [0x0000f] in D:\agent\_work\2\s\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:144 
  at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[TElement].OnElementChanged (Xamarin.Forms.Platform.iOS
.ElementChangedEventArgs`1[TElement] e) [0x0002c] in <9a5948fff8254b13a3d593c76c73b9b1>:0 
  at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[TElement].SetElement (TElement element) [0x00118] in <9a5948fff8254b13a3d593c76c73b9b1>:0 
  at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[TElement].Xamarin.Forms.Platform.iOS.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00000] in <9a5948fff8254b13a3d593c76c73b9b1>:0 
  at Xamarin.Forms.Platform.iOS.ListViewRenderer+UnevenListViewDataSource.CalculateHeightForCell (UIKit.UITableView tableView, Xamarin.Forms.Cell cell) [0x00035] in D:\agent\_work\2\s\Xamarin.Forms.Platform.iOS\Renderers\ListViewRenderer.cs:745 
  at Xamarin.Forms.Platform.iOS.ListViewRenderer+UnevenListViewDataSource.GetEstimatedRowHeight (UIKit.UITableView table) [0x00095] in D:\agent\_work\2\s\Xamarin.Forms.Platform.iOS\Renderers\ListViewRenderer.cs:689 
  at Xamarin.Forms.Platform.iOS.ListViewRenderer.UpdateEstimatedRowHeight () [0x0005f] in D:\agent\_work\2\s
\Xamarin.Forms.Platform.iOS\Renderers\ListViewRenderer.cs:399 
  at Xamarin.Forms.Platform.iOS.ListViewRenderer.UpdateItems (System.Collections.Specialized.NotifyCollectionChangedEventArgs e, System.Int32 section, System.Boolean resetWhenGrouped) [0x000bc] in D:\agent\_work\2\s\Xamarin.Forms.Platform.iOS\Renderers\ListViewRenderer.cs:527 
  at Xamarin.Forms.Platform.iOS.ListViewRenderer.OnCollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00000] in D:\agent\_work\2\s\Xamarin.Forms.Platform.iOS\Renderers\ListViewRenderer.cs:298 
  at Xamarin.Forms.Internals.TemplatedItemsList`2[TView,TItem].OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x0000a] in <1feef6e00a314921bf9a29876c83b540>:0 
  at Xamarin.Forms.Internals.TemplatedItemsList`2[TView,TItem].OnProxyCollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e, System.Boolean fixWindows) [0x0047b] in <1feef6e00
a314921bf9a29876c83b540>:0 
  at Xamarin.Forms.Internals.TemplatedItemsList`2[TView,TItem].OnProxyCollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00000] in <1feef6e00a314921bf9a29876c83b540>:0 
  at Xamarin.Forms.ListProxy.OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x0000a] in D:\agent\_work\2\s\Xamarin.Forms.Core\ListProxy.cs:233 
  at Xamarin.Forms.ListProxy+<>c__DisplayClass33_0.<OnCollectionChanged>b__0 () [0x00018] in D:\agent\_work\2\s\Xamarin.Forms.Core\ListProxy.cs:206 
  at Xamarin.Forms.ListProxy.OnCollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x000a0] in D:\agent\_work\2\s\Xamarin.Forms.Core\ListProxy.cs:225 
  at Xamarin.Forms.ListProxy+WeakNotifyProxy.OnCollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00031] in D:\agent\_work\2\s\Xamarin.Forms.Core\ListProxy.cs:394 
  at System.Collections.ObjectModel.ObservableCollection`1[T].OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x0000f] in <229b28fdde8a4b7a9f48acaea4186a74>:0 
  at System.Collections.ObjectModel.ObservableCollection`1[T].OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedAction action, System.Object item, System.Int32 index) [0x00009] in <229b28fdde8a4b7a9f48acaea4186a74>:0 
  at System.Collections.ObjectModel.ObservableCollection`1[T].InsertItem (System.Int32 index, T item) [0x00024] in <229b28fdde8a4b7a9f48acaea4186a74>:0 
  at System.Collections.ObjectModel.Collection`1[T].Insert (System.Int32 index, T item) [0x0002f] in <136edfc8e644410eb152bce382121c61>:0 
  at Egg.Poached.Core.ViewModels.HomeVm+<>c__DisplayClass36_1.<.ctor>b__19 () [0x0005b] in C:\Users\TejasViswanath\Source\Repos\Egg.Poached\Egg.Poached.Core\ViewModels\HomeVm.cs:164
Comment 38 matteo 2017-11-28 13:40:32 UTC
Error not solved in last version.

Maybe is related, if I write a renderer like this:

public override UITableViewCell GetCell(Cell item, UITableViewCell reusableCell, UITableView tv)
	{
		var cell = base.GetCell(item, reusableCell, tv);
		if (cell != null)
		{
			cell.SelectionStyle = UITableViewCellSelectionStyle.Blue;
		}
		return cell;
	}

I have this error instead of "NullReferenceException":
"xamarin item index was out of range. must be non-negative and less than the size of the collection. parameter name: index" on the 'var cell = base.GetCell(item, reusableCell, tv);' row.
(using a grouped listview, RetainElement, HasUnevenRows)

With XF version 2.3.5.239-pre3 is working

Hope it can helps
Comment 39 Ammar Mheir 2017-12-04 16:51:33 UTC
We also still seem to be experiencing this same issue. When HasUnevenRows is set to False, we are unable to replicate. Below is the stack trace and version information. We verified this is also occuring on the latest Xamarin.Forms 2.5 as well.  

>System.NullReferenceException: Object reference not set to an instance of an object
>  at Xamarin.Forms.Platform.iOS.EventTracker.LoadRecognizers () [0x0005d] in <47a2c3907d3d46f58fede29f6c11765e>:0
>  at Xamarin.Forms.Platform.iOS.EventTracker.OnElementChanged (System.Object sender, Xamarin.Forms.Platform.iOS.VisualElementChangedEventArgs e) [0x0004e] in <47a2c3907d3d46f58fede29f6c11765e>:0
>  at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[TElement].OnElementChanged (Xamarin.Forms.Platform.iOS.ElementChangedEventArgs`1[TElement] e) [0x0002c] in <47a2c3907d3d46f58fede29f6c11765e>:0
>  at Xamarin.Forms.Platform.iOS.ViewRenderer`2[TView,TNativeView].OnElementChanged (Xamarin.Forms.Platform.iOS.ElementChangedEventArgs`1[TElement] e) [0x00000] in <47a2c3907d3d46f58fede29f6c11765e>:0
>  at Xamarin.Forms.Platform.iOS.ImageRenderer.<>n__0 (Xamarin.Forms.Platform.iOS.ElementChangedEventArgs`1[TElement] e) [0x00000] in <47a2c3907d3d46f58fede29f6c11765e>:0
>  at Xamarin.Forms.Platform.iOS.ImageRenderer+<OnElementChanged>d__2.MoveNext () [0x000d6] in <47a2c3907d3d46f58fede29f6c11765e>:0
>--- End of stack trace from previous location where exception was thrown ---
>  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.3.0.47/src/mono/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:151
>  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_0 (System.Object state) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.3.0.47/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1018
>  at UIKit.UIKitSynchronizationContext+<Post>c__AnonStorey0.<>m__0 () [0x00000] in /Users/builder/data/lanes/5520/51128b8c/source/xamarin-macios/src/UIKit/UIKitSynchronizationContext.cs:24
>  at Foundation.NSAsyncActionDispatcher.Apply () [0x00000] in /Users/builder/data/lanes/5520/51128b8c/source/xamarin-macios/src/Foundation/NSAction.cs:163
>--- End of stack trace from previous location where exception was thrown ---
>  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/data/lanes/5520/51128b8c/source/xamarin-macios/src/UIKit/UIApplication.cs:79
>  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Users/builder/data/lanes/5520/51128b8c/source/xamarin-macios/src/UIKit/UIApplication.cs:63
>  at GuitarCenterNativeApp.iOS.Application.Main (System.String[] args) [0x00002] in /Users/jaridgoodwin/Desktop/GuitarCenterOnPrem/iOS/Main.cs:19

##Version Information

=== Visual Studio Professional 2017 for Mac ===

Version 7.2.2 (build 11)
Installation UUID: 7fb0c39f-4886-46d8-af42-d03b32a4dca2
Runtime:
                Mono 5.4.1.6 (2017-06/1f4613aa1ac) (64-bit)
                GTK+ 2.24.23 (Raleigh theme)

                Package version: 504010006

=== Apple Developer Tools ===

Xcode 9.1 (13532)
Build 9B55

=== Xamarin.iOS ===

Version: 11.3.0.47 (Visual Studio Professional)
Hash: 51128b8c
Branch: xcode9.1
Build date: 2017-10-31 22:42:13-0400

=== Xamarin.Android ===

Version: 8.0.2.1 (Visual Studio Professional)
Android SDK: /Users/jaridgoodwin/Library/Developer/Xamarin/android-sdk-macosx
                Supported Android versions:
                                7.1 (API level 25)
                                8.0 (API level 26)

SDK Tools Version: 25.2.5
SDK Platform Tools Version: 25.0.4
SDK Build Tools Version: 25.0.2

Java SDK: /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)

=== Xamarin.Mac ===

Version: 3.8.1.0 (Visual Studio Professional)


=== Build Information ===

Release ID: 702020011
Git revision: b604c37c5a4a2f0919b45ffbe2aaad9fe040af31
Build date: 2017-11-01 08:31:43-04
Xamarin addins: d57dc14cbd4eb166ee62bab585965ab78d3650bc
Build lane: monodevelop-lion-d15-4

=== Operating System ===

Mac OS X 10.13.1
Darwin 17.2.0 Darwin Kernel Version 17.2.0
    Fri Sep 29 18:27:05 PDT 2017
    root:xnu-4570.20.62~3/RELEASE_X86_64 x86_64

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