Bug 59716 - NRE on ListView's cell update when templated with grid and label
Summary: NRE on ListView's cell update when templated with grid and label
Status: RESOLVED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: iOS (show other bugs)
Version: 2.4.0
Hardware: PC Windows
: Normal major
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-09-25 08:21 UTC by mailcannon
Modified: 2018-01-25 13:21 UTC (History)
7 users (show)

Tags: hasunevenrows, listview, ac
Is this bug a regression?: ---
Last known good build:


Attachments
repro project (186.09 KB, application/x-7z-compressed)
2017-09-25 08:21 UTC, mailcannon
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:
RESOLVED FIXED

Description mailcannon 2017-09-25 08:21:37 UTC
Created attachment 24908 [details]
repro project

I have this xaml. And items adding by an event(i.e. asynchronously).

    <StackLayout>
        <Button Text="Update" Command="{Binding UpdateListCommand}" />
        <ListView ItemsSource="{Binding Items}"
                  HasUnevenRows="True">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <Grid>
                            <Label
                                BackgroundColor="Transparent"
                                Text="{Binding }"
                                VerticalOptions="Center"
                                HorizontalOptions="Center"/>
                        </Grid>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </StackLayout>

When HasUnevenRows="True", application crashes exactly on third click on "Update" button with NullReferenceException in LabelRenderer. 
When i set HasUnevenRows="False" or remove the Grid or make list updating synchronous - everything working fine.
Repro project included
Comment 1 Paul DiPietro [MSFT] 2017-09-25 19:33:11 UTC
Verified testing the behavior against 2.4.0-pre3.
Comment 2 mailcannon 2017-10-02 11:30:25 UTC
still crashes with 2.4.0.282
Comment 3 mailcannon 2017-10-03 09:37:25 UTC
the workarround i found is:

to set CachingStrategy="RecycleElement" ||
to set HasUnevenRows="False" ||
to remove the Grid from viewcell template
Comment 4 mailcannon 2017-10-03 09:41:35 UTC
I changed all ListView's behaviours to CachingStrategy="RecycleElement", bun unfortunatelly, app is still crashes rarely with labels that are not in ViewCell template.

Xamarin.Forms.Platform.iOS.LabelRenderer.UpdateText()
Xamarin.Forms.Platform.iOS.LabelRenderer.OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
<Module>.invoke_void_object_PropertyChangedEventArgs(object, PropertyChangedEventArgs)(wrapper delegate-invoke)
Xamarin.Forms.BindableObject.OnPropertyChanged(string propertyName)
Xamarin.Forms.Element.OnPropertyChanged(string propertyName)
Xamarin.Forms.BindableObject.SetValueActual(BindableProperty property, BindableObject.BindablePropertyContext context, object value, bool currentlyApplying, SetValueFlags attributes, bool silent)
Xamarin.Forms.BindableObject.SetValueCore(BindableProperty property, object value, SetValueFlags attributes, BindableObject.SetValuePrivateFlags privateAttributes)
Xamarin.Forms.BindingExpression.ApplyCore(object sourceObject, BindableObject target, BindableProperty property, bool fromTarget)
Xamarin.Forms.BindingExpression.Apply(bool fromTarget)
Xamarin.Forms.BindingExpression.BindingExpressionPart.<PropertyChanged>b__47_0()
Foundation.NSAsyncActionDispatcher.Apply()
UIKit.UIApplication.UIApplicationMain(int, string[], intptr, intptr)(wrapper managed-to-native)
UIKit.UIApplication.Main(string[] args, IntPtr principal, IntPtr delegate)
UIKit.UIApplication.Main(string[] args, string principalClassName, string delegateClassName)
TimeTracker.iOS.Application.Main(string[] args)

as you can see, crashes after OnElementPropertyChanged call as well aw when label is in ViewCell template.
Comment 5 mailcannon 2017-10-03 09:44:58 UTC
Also, i found out that if i remove any labels from my own application, its still crashes with ObjectDisposedException on images that are left in ViewCell template.
Comment 6 mailcannon 2017-10-03 09:50:52 UTC
In repro project, if change
 
<Label
  BackgroundColor="Transparent"
  Text="{Binding }"
  VerticalOptions="Center"
  HorizontalOptions="Center"/>

with 

<Image
  Source="Icon-76"
  BackgroundColor="Transparent"
  VerticalOptions="Center"
  HorizontalOptions="Center"/>

then app is crashing after few updates with 

NSInternalInconsistencyException Reason: table view row height must not be negative - provided height for index path (<UIMutableIndexPath 0x7fa282b88110> 2 indexes [0, 0]) is -1.000000

no matter what CachingStrategy is set.
Comment 7 mailcannon 2017-10-03 09:51:24 UTC
please, do something, this is not stable at all
Comment 8 cjw1115@hotmail.com 2017-10-24 08:31:18 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 9 otyq08 2017-11-13 21:23:11 UTC
I'm also running into that problem, please fix.
Mailcannon please set the regression flag to true.
Comment 10 mailcannon 2017-11-21 07:10:13 UTC
repro project is not crashing anymore with 2.5.0.91635
Comment 11 Paul DiPietro [MSFT] 2017-11-21 14:11:36 UTC
Thank you for the update; presumed resolved.
Comment 12 Darryl Leckenby 2018-01-25 13:21:24 UTC
If it is of any use to others still having issues that seem very similar to this:

I was researching around NRE's I was having around a listview bound to an observable collection of objects including a list: I resolved this issue by removing the use of the grid in the data template.

Note: I had this error previously which was resolved by a roll-back to 2.4.X versions. I have found another scenario producing the same error.

Using HasUnevenRows=false on the listview did remove the problem but formatting quirks were not acceptable for the product. This led me to realise the collections and binding are not the cause of the error, and it's more likely to be some kind of height or dimensional calc/UI method under the hood that is tripping the error. So playing around with different layout objects within the ViewCell narrowed down a work-around that was acceptable. I moved from using a grid to a stack layout to replicate the positioning I wanted.

For the projects here we have earmarked this to look into again in next release of Xamarin and produce a reproduction project if still there. It sounds like a pre-release is covering NRE bugs in this area.

At the time of writing I had tried both the latest 2.5.X and had tried rolling back to  various 2.4.X versions of Xamarin.forms.