We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

CRASH: Null Reference Exception in MeasureSize.Convert

Hi,

We are intermittently seeing a crash on both Android and iOS in the MeasureSize method when trying to AutoFit items in a list view. This is a showstopper for us as we are unable to find a way around this.

We are using SfListView version 15.2.0.46.

I have pasted the stack traces below.

Any ideas of what might be causing this?

-Jeff

iOS stack trace:
System.NullReferenceException: Object reference not set to an instance of an object
Syncfusion.ListView.XForms.iOS.MeasureSize.Convert(View view, VisualElement valid)
Syncfusion.ListView.XForms.iOS.MeasureSize.CalculateSize(SfListView listview, View content, Size viewSize)
Syncfusion.ListView.XForms.LayoutBase.GetAutoFitItemSize(ListViewItemInfoBase itemInfo, ref double itemSize, double itemSpacing, int spanCount)
Syncfusion.ListView.XForms.LinearLayout.GetAutoFitItemSize(ListViewItemInfoBase itemInfo, ref double itemSize, double itemSpacing)
Syncfusion.ListView.XForms.LinearLayout.SetRowHeight(ListViewItemInfo itemInfo, int index, ref double size, double itemSpacing)
Syncfusion.ListView.XForms.LinearLayout.SetRowHeight(ListViewItemInfo itemInfo, double itemSpacing)
Syncfusion.ListView.XForms.LinearLayout.EnsureItems(VisibleLinesCollection visibleLines)
Syncfusion.ListView.XForms.VisualContainer.EnsureItems()
Syncfusion.ListView.XForms.VisualContainer.OnSizeAllocated(double width, double height)
Xamarin.Forms.VisualElement.SizeAllocated(double width, double height)
Xamarin.Forms.Layout.ForceLayout()
Syncfusion.ListView.XForms.SfListView.RefreshView()
Syncfusion.ListView.XForms.SfListView.OnItemsSourceChanged(BindableObject bindable, object oldValue, object newValue)
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)

Android Stack Trace:
Xamarin caused by: android.runtime.JavaProxyThrowable: System.NullReferenceException: Object reference not set to an instance of an object
Syncfusion.ListView.XForms.Android.MeasureSize.Convert(View view, VisualElement valid)<45491835247e45198eb2b4104a22ce57>:0
Syncfusion.ListView.XForms.Android.MeasureSize.CalculateSize(SfListView listview, View content, Size viewSize)<45491835247e45198eb2b4104a22ce57>:0
Syncfusion.ListView.XForms.LayoutBase.GetAutoFitItemSize(ListViewItemInfoBase itemInfo, ref double itemSize, double itemSpacing, int spanCount)<4b5a7cea83394af5945b5c1c0e00b615>:0
Syncfusion.ListView.XForms.LinearLayout.GetAutoFitItemSize(ListViewItemInfoBase itemInfo, ref double itemSize, double itemSpacing)<4b5a7cea83394af5945b5c1c0e00b615>:0
Syncfusion.ListView.XForms.LinearLayout.SetRowHeight(ListViewItemInfo itemInfo, int index, ref double size, double itemSpacing)<4b5a7cea83394af5945b5c1c0e00b615>:0
Syncfusion.ListView.XForms.LinearLayout.SetRowHeight(ListViewItemInfo itemInfo, double itemSpacing)<4b5a7cea83394af5945b5c1c0e00b615>:0
Syncfusion.ListView.XForms.LinearLayout.EnsureItems(VisibleLinesCollection visibleLines)<4b5a7cea83394af5945b5c1c0e00b615>:0
Syncfusion.ListView.XForms.VisualContainer.EnsureItems()<4b5a7cea83394af5945b5c1c0e00b615>:0
Syncfusion.ListView.XForms.VisualContainer.OnSizeAllocated(double width, double height)<4b5a7cea83394af5945b5c1c0e00b615>:0
Xamarin.Forms.VisualElement.SizeAllocated(double width, double height)<937957814f5d45be82b66795cb584841>:0
Xamarin.Forms.Layout.ForceLayout()<937957814f5d45be82b66795cb584841>:0
Syncfusion.ListView.XForms.SfListView.RefreshView()<4b5a7cea83394af5945b5c1c0e00b615>:0
Syncfusion.ListView.XForms.SfListView.OnItemsSourceChanged(BindableObject bindable, object oldValue, object newValue)<4b5a7cea83394af5945b5c1c0e00b615>:0
Xamarin.Forms.BindableObject.SetValueActual(BindableProperty property, BindableObject.BindablePropertyContext context, object value, bool currentlyApplying, SetValueFlags attributes, bool silent)<937957814f5d45be82b66795cb584841>:0
Xamarin.Forms.BindableObject.SetValueCore(BindableProperty property, object value, SetValueFlags attributes, BindableObject.SetValuePrivateFlags privateAttributes)<937957814f5d45be82b66795cb584841>:0
Xamarin.Forms.BindingExpression.ApplyCore(object sourceObject, BindableObject target, BindableProperty property, bool fromTarget)<937957814f5d45be82b66795cb584841>:0
Xamarin.Forms.BindingExpression.Apply(bool fromTarget)<937957814f5d45be82b66795cb584841>:0
Xamarin.Forms.BindingExpression.BindingExpressionPart.<PropertyChanged>b__47_0()<937957814f5d45be82b66795cb584841>:0
Java.Lang.Thread.RunnableImplementor.Run()<d855bac285f44dda8a0d8510b679b1e2>:0
Java.Lang.IRunnableInvoker.n_Run(IntPtr jnienv, IntPtr native__this)<d855bac285f44dda8a0d8510b679b1e2>:0
at (wrapper dynamic-method) System.Object:8ebe438e-46a8-47a2-940b-8543d0c14404 (intptr,intptr)
mono.java.lang.RunnableImplementor.n_run(Native Method)
mono.java.lang.RunnableImplementor.run()RunnableImplementor.java:30
android.os.Handler.handleCallback()Handler.java:751
android.os.Handler.dispatchMessage()Handler.java:95
android.os.Looper.loop()Looper.java:154
android.app.ActivityThread.main()ActivityThread.java:6688
java.lang.reflect.Method.invoke(Native Method)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run()ZygoteInit.java:1468
com.android.internal.os.ZygoteInit.main()ZygoteInit.java:1358

8 Replies

DB Dinesh Babu Yadav Syncfusion Team July 28, 2017 09:45 AM UTC

Hi Jeff, 
 
Thank you for using Syncfusion Products.   
   
Based on the given stacks trace, we suspect that the reported issue “Exception throws when AutoFitMode is Height in SfListView” arises due to SfListViewRenderer might not be initialized in renderer projects. And, you may have not add the assemblies needed to initialize the SfListView in each renderer project for both Android and iOS renderer project. So, we recommend you to refer the following UG documentation links to initialize the SfListView renderer in each platform to resolve the issue at the sample level. 
 
    
If the issue still persist at your end, we request you to replicate the issue in a sample and revert us with the replication procedure. Also, could you please share and check with the below information’s at your end. So, that we could able to analyze the issue better and update you an appropriate solution.   
   
  • Could you please check whether you have updated the binding context for the SfListView properly?
  • Could you please share in which layout does the issue replicates and please share the replication procedure too?
  • Could you please share the application scenario in which the reported issue occurs?
  • Could you please share the Xamarin Forms version?. We have ensured in Xamarin Forms v2.3.3.180.?
 
Please let us know if you require further assistance.   
   
Regards,   
Dinesh Babu Yadav 



JB Jeff Bowman July 28, 2017 01:19 PM UTC

Thank you Dinesh,

We have confirmed that we are initializing the renders correctly. This issue does not happen all the time, but is intermittent, as it will just seem to happen all of a sudden.

We are using a newer version of Xamarin forms: 2.3.5.256-pre6. Unfortunately, we are not able to downgrade as they fixed a major bug for us in these pre-releases.

One thing we are doing that might be of note is expanding and collapsing the listview cell on click (to show additional content), Occasionally we notice that the cell expands, but the content doesn't show up, I am wondering if this leads to the crash.

I have attached a text file with our layout. I pasted both the data template and how we use the listview into the same file.

We will work on finding 'reproducible steps' to share with you.

Regards,

-Jeff




Attachment: layoutexample_6fbc0eb0.zip


JB Jeff Bowman July 30, 2017 05:33 PM UTC

Hi Dinesh,

I was able to find a way to reproduce this:

- Open the page that has the listview, the listview ItemsSource is loaded via an API call to our web service.

- Before the API returns it's response, navigate away from the page

- Navigate back to the page

- Observe: When the API response returns, it crashes with the error reported.

As a note, I was able to find a workaround to this 'crash'. On the 'Disappearing' event of the content page. If I dispose of the list view. It will prevent the crash the next time the page loads. The problem with this, is that the next time I load the page, it can take ~5-6 seconds even after our API to response to display the data (even if it is only 1 item).

I hope this helps!

Regards,

-Jeff


 



DB Dinesh Babu Yadav Syncfusion Team August 1, 2017 03:18 AM UTC

Hi Jeff, 
 
Sorry for the inconvenience caused. 
 
We have analyzed the reported issue “Exception throws when AutoFitMode is Height in SfListView” with the provided information’ s at our end. In our sample, we have loaded the SfListView in a Detail page of MasterDetailPage and on tapping the item, it navigates to another page(ContentPage). And, when navigated back to DetailPage, we have loaded the ItemsSource property again as reported. But we are unable to find any crash as reported at our end and also, the items gets loaded as expected. 
 
  • Could you please share that whether the issue replicates only in particular platform such as Android only or others too?.
  • Have you loaded the same collection to the ItemsSource when navigate back to the Detail page or new collection?
  • If possible, could you please reproduce the issue in a sample? which would help us to analyze the issue better and update you an appropriate solution.
 
Regards, 
Dinesh Babu Yadav 
 



EM Emil August 7, 2017 01:40 AM UTC

I am having same problem when I use listview in a popuppage, if I dont dispose listview when the popup is popped and try to open the popup, it causes crashes using autofit mode.

@Jeff: could you figure out exact problem and found a workaround? I am using latest stable of XF, not pre release and it occurs with that also



JB Jeff Bowman August 7, 2017 03:45 AM UTC

Hi Emil,By what I am seeing, there seems to be some issues around async loading of the ListView ItemsSource from our PageModels. I am not sure if this issue is specific to our MVVM framework (We are using FreshMvvm), but when we navigate away from the page the PageModel, the async commands in progress are not ended automatically (they will finish even if the page is no longer on the stack). So the next time the page loads, it seems as though the ListView is getting confused and tries to load the items from the previous time the PageModel was loaded (which most likely have since been cleaned up) and it crashes with the null reference in MeasureSize.Convert.  As far as a workaround, the 'Dispose' of the ListView on Disappearing seemed to help.. but of course when we would not navigate away from the page completely, but simply a modal popped up, when the modal went away, the app would crash due to the ListView no longer being there. So I got rid of the Dispose() on disappear. What I tried next was in my async Command (which I had attached to a TaskCompletionSource), I tried to cancel the Task on Dissappear. That seemed to help a bit.. but there seemed to be a race condition where occasionally we would see this issue come up still.. My latest attempt at trying to get rid of this race condition, I implemented cancellation token support from our Command to our API Client into the REST client framework (We use RestSharp). I can't say for sure if this helped completely yet as we haven't had any test time with this yet, but I couldn't crash the app in my development environment, but maybe some of the above may help you :).In either case, I think this crash could easily be prevented by a Null check in this MeasureSize.Convert method (most likely on the view..).Dinesh,Sorry for the late reply!To answer your questions:Could you please share that whether the issue replicates only in particular platform such as Android only or others too?. This happens at least on iOS and Android, our app doesn't support any other platforms at this time.Have you loaded the same collection to the ItemsSource when navigate back to the Detail page or new collection? I am not quite sure what you mean by this, but I believe we are trying to load a new collection, but perhaps due to our async calls (see my description above to Emil) its possible it is trying to load the old one.If possible, could you please reproduce the issue in a sample? which would help us to analyze the issue better and update you an appropriate solution. I will try to find the time to do this, but my schedule is incredibly tight right now. In our App, it was a ContentPage where this crash occurred, we went from Master Detail >> Content Page (page using ListView) >> Master Detail >> Content Page (page using ListView) >> CRASH. If the problem is what I think it might be, if you create a Content page with a PageModel, and asynchronously load the ItemsSource when the Page loads (from the PageModel) and before the async call returns, navigate away from the Page. Then navigate back to the page, and wait for it to load. This is where we are seeing the crash.Best Regards,-Jeff


JB Jeff Bowman August 7, 2017 03:46 AM UTC

Hi Emil,

By what I am seeing, there seems to be some issues around async loading of the ListView ItemsSource from our PageModels. I am not sure if this issue is specific to our MVVM framework (We are using FreshMvvm), but when we navigate away from the page the PageModel, the async commands in progress are not ended automatically (they will finish even if the page is no longer on the stack). So the next time the page loads, it seems as though the ListView is getting confused and tries to load the items from the previous time the PageModel was loaded (which most likely have since been cleaned up) and it crashes with the null reference in MeasureSize.Convert.  

As far as a workaround, the 'Dispose' of the ListView on Disappearing seemed to help.. but of course when we would not navigate away from the page completely, but simply a modal popped up, when the modal went away, the app would crash due to the ListView no longer being there. So I got rid of the Dispose() on disappear. What I tried next was in my async Command (which I had attached to a TaskCompletionSource), I tried to cancel the Task on Dissappear. That seemed to help a bit.. but there seemed to be a race condition where occasionally we would see this issue come up still.. My latest attempt at trying to get rid of this race condition, I implemented cancellation token support from our Command to our API Client into the REST client framework (We use RestSharp). I can't say for sure if this helped completely yet as we haven't had any test time with this yet, but I couldn't crash the app in my development environment, but maybe some of the above may help you :).

In either case, I think this crash could easily be prevented by a Null check in this MeasureSize.Convert method (most likely on the view..).

Dinesh,

Sorry for the late reply!

To answer your questions:

  • Could you please share that whether the issue replicates only in particular platform such as Android only or others too?. This happens at least on iOS and Android, our app doesn't support any other platforms at this time.
  • Have you loaded the same collection to the ItemsSource when navigate back to the Detail page or new collection? I am not quite sure what you mean by this, but I believe we are trying to load a new collection, but perhaps due to our async calls (see my description above to Emil) its possible it is trying to load the old one.
  • If possible, could you please reproduce the issue in a sample? which would help us to analyze the issue better and update you an appropriate solution. I will try to find the time to do this, but my schedule is incredibly tight right now. In our App, it was a ContentPage where this crash occurred, we went from Master Detail >> Content Page (page using ListView) >> Master Detail >> Content Page (page using ListView) >> CRASH. If the problem is what I think it might be, if you create a Content page with a PageModel, and asynchronously load the ItemsSource (which is bound to a property in the PageModel) when the Page loads (from the PageModel) and before the async call returns, navigate away from the Page. Then navigate back to the page, and wait for it to load. This is where we are seeing the crash.
Best Regards,

-Jeff


DB Dinesh Babu Yadav Syncfusion Team August 9, 2017 04:09 AM UTC

Hi Jeff, 
 
Sorry for the inconvenience.     
    
Based on the provided information, we have analyzed all the possible scenarios to replicate the reported issue “Exception throws when AutoFitMode is Height in SfListView while navigating in MasterDetail Page” at our end. But, we are unable to reproduce the issue at our end. We have created a support incident under your account to hold the meeting. Please log on to our support website to check for further updates.          
    
    
Regards,    
Dinesh Babu Yadav  


Loader.
Up arrow icon