Bug 58645 - [iOS] NRE Thrown When ListView Items Are Replaced By Items With a Different Template
Summary: [iOS] NRE Thrown When ListView Items Are Replaced By Items With a Different T...
Status: VERIFIED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: iOS ()
Version: 2.3.5
Hardware: PC Windows
: Normal critical
Target Milestone: 15.5
Assignee: Samantha Houts [MSFT]
URL:
: 58080 ()
Depends on:
Blocks:
 
Reported: 2017-08-08 15:54 UTC by Jimmy [MSFT]
Modified: 2017-11-03 12:50 UTC (History)
6 users (show)

Tags: ac ios ListView HasUnevenRows TemplateSelector fr
Is this bug a regression?: Yes
Last known good build: 2.3.4.247


Attachments
repro project (273.13 KB, application/x-zip-compressed)
2017-08-08 15:54 UTC, Jimmy [MSFT]
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
VERIFIED FIXED

Description Jimmy [MSFT] 2017-08-08 15:54:08 UTC
Created attachment 24082 [details]
repro project

### Overview
An NRE will be thrown on iOS if a ListView with HasUnevenRows set to true clears its ItemSource and adds new items with a different template than the previous ones:

> Xamarin.Forms.Platform.iOS.Platform.GetRenderer (Xamarin.Forms.VisualElement bindable) [0x00000] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.iOS\Platform.cs:199 
> Xamarin.Forms.Platform.iOS.RendererPool.ClearRenderers (Xamarin.Forms.Platform.iOS.IVisualElementRenderer renderer) [0x00027] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.iOS\RendererPool.cs:94 
> Xamarin.Forms.Platform.iOS.RendererPool.UpdateNewElement (Xamarin.Forms.VisualElement newElement) [0x0006c] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.iOS\RendererPool.cs:74 
> 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 
> 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 
> Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[TElement].OnElementChanged (Xamarin.Forms.Platform.iOS.ElementChangedEventArgs`1[TElement] e) [0x00020] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.iOS\VisualElementRenderer.cs:269 
> Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[TElement].SetElement (TElement element) [0x00110] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.iOS\VisualElementRenderer.cs:188 
> Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[TElement].Xamarin.Forms.Platform.iOS.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00000] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.iOS\VisualElementRenderer.cs:139 
> 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:723 
> Xamarin.Forms.Platform.iOS.ListViewRenderer+UnevenListViewDataSource.GetEstimatedRowHeight (UIKit.UITableView table) [0x0005d] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.iOS\Renderers\ListViewRenderer.cs:687 
> Xamarin.Forms.Platform.iOS.ListViewRenderer.UpdateEstimatedRowHeight () [0x00045] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.iOS\Renderers\ListViewRenderer.cs:382 
> Xamarin.Forms.Platform.iOS.ListViewRenderer.UpdateItems (System.Collections.Specialized.NotifyCollectionChangedEventArgs e, System.Int32 section, System.Boolean resetWhenGrouped) [0x00055] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.iOS\Renderers\ListViewRenderer.cs:511 
> 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:300 
> Xamarin.Forms.Internals.TemplatedItemsList`2[TView,TItem].OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x0000a] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\TemplatedItemsList.cs:758 
> Xamarin.Forms.Internals.TemplatedItemsList`2[TView,TItem].OnProxyCollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e, System.Boolean fixWindows) [0x0047a] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\TemplatedItemsList.cs:1101 
> Xamarin.Forms.Internals.TemplatedItemsList`2[TView,TItem].OnProxyCollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00000] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\TemplatedItemsList.cs:955 
> Xamarin.Forms.ListProxy.OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x0000a] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\ListProxy.cs:233 
> Xamarin.Forms.ListProxy+<>c__DisplayClass33_0.<OnCollectionChanged>b__0 () [0x00018] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\ListProxy.cs:206 
> Xamarin.Forms.ListProxy.OnCollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x000a0] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\ListProxy.cs:225 
> 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 
> System.Collections.ObjectModel.ObservableCollection`1[T].OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x0000f] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.12.0.14/src/mono/mcs/class/referencesource/System/compmod/system/collections/objectmodel/observablecollection.cs:288 
> System.Collections.ObjectModel.ObservableCollection`1[T].OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedAction action, System.Object item, System.Int32 index) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.12.0.14/src/mono/mcs/class/referencesource/System/compmod/system/collections/objectmodel/observablecollection.cs:351 
> System.Collections.ObjectModel.ObservableCollection`1[T].InsertItem (System.Int32 index, T item) [0x00024] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.12.0.14/src/mono/mcs/class/referencesource/System/compmod/system/collections/objectmodel/observablecollection.cs:219 
> System.Collections.ObjectModel.Collection`1[T].Add (T item) [0x00020] in /Library/Frameworks/Xamarin.iOS.framework/Versions/10.12.0.14/src/mono/mcs/class/referencesource/mscorlib/system/collections/objectmodel/collection.cs:67 
> LVCrash.TestPage.<.ctor>b__4_0 () [0x0000d] in C:\Users\jigarrid\Xamarin\Bugs\58080 lv items\LVCrash\LVCrash\LVCrash\TestPage.cs:41 
> Xamarin.Forms.Command+<>c__DisplayClass3_0.<.ctor>b__0 (System.Object o) [0x00000] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\Command.cs:73 
> Xamarin.Forms.Command.Execute (System.Object parameter) [0x00000] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\Command.cs:107 
> Xamarin.Forms.Button.SendClicked () [0x00000] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\Button.cs:116 
> Xamarin.Forms.Platform.iOS.ButtonRenderer.OnButtonTouchUpInside (System.Object sender, System.EventArgs eventArgs) [0x00011] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.iOS\Renderers\ButtonRenderer.cs:125 
> UIKit.UIControlEventProxy.Activated () [0x00007] in /Users/builder/data/lanes/4991/bf350ba5/source/xamarin-macios/src/UIKit/UIControl.cs:38 


This is a new regression introduced in 2.3.5. It might be a result of this fix[1] that sets the renderer's element to null which results in null being passed to Platform.GetRenderer here[2].

[1] https://github.com/xamarin/Xamarin.Forms/pull/894
[2] https://github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.Platform.iOS/RendererPool.cs#L94


### Steps to Reproduce
1. Run the attached iOS project
2. Press "Switch Items"


### Expected Results
The original ListView items will be cleared and single new item with a different layout will be added.


### Actual Results
The app crashes. You might need to set VS to break on all CLR exceptions in order to see the full stack trace.


### Workaround
Set HasUnevenRows to false or set a RowHeight.


### Version Tests
2.3.6.124   BAD
2.3.5-pre6  BAD
2.3.4.247   GOOD
Comment 1 Jimmy [MSFT] 2017-08-08 17:14:16 UTC
*** Bug 58080 has been marked as a duplicate of this bug. ***
Comment 2 Mathias Hartner 2017-08-09 07:46:05 UTC
Thanks for the elaboration Jimmy. When will this issue be resolved?
Can you say in which release and the approximate period?
Comment 3 Samantha Houts [MSFT] 2017-08-11 19:51:59 UTC
https://github.com/xamarin/Xamarin.Forms/pull/1095
Comment 4 Rui Marinho 2017-08-15 15:55:55 UTC
Should be fixed on 2.4.0
Comment 5 Swati Gangrade 2017-11-03 12:50:31 UTC
Bug is retested and verified in below build Version- 

Microsoft Visual Studio Enterprise 2017 d15rel Version 15.5.0 Preview 3.0 [27029.9000.merge]
Microsoft .Net Framework Version 4.7.02046
Xamarin -4.8.0.713 (f0e7af2)
Xamarin Designer - 4.8.143 (14e3edba0)
Xamarin.Android SDK  8.1.0.22 (HEAD/0baf02a75)
Xamarin.iOS and Xamarin.Mac SDK   11.4.0.98 (25c6ba1)


Detailed Build Info- https://gist.github.com/GLjackyvaswani/fa75833c5778a37e5434d6d7523872f8

Screencast- https://www.screencast.com/t/rvlTtMbl

It is working fine with the latest Forms version 
2.5.0.19271-pre2 good
2.4.0.38779 good

Its throwing NRE  with above mentioned builds i.e.
2.3.6.124   BAD
2.3.5-pre6  BAD

Hence marking as verified