Looks like a bug to me in version 2017.1.1220.233...
The Issue
Here is my model, I have a collection of these;
public
class
Site
{
public
int
SiteId {
get
;
set
; }
public
string
SiteName {
get
;
set
; }
public
string
SiteDetailText {
get
;
set
; }
public
string
FarmName {
get
;
set
; }
}
Here is the XAML definition of the RadListView;
<
telerikui:RadListView
x:Name
=
"SitesList"
ItemsSource
=
"{Binding MySites}"
>
<
telerikui:RadListView.ItemTemplate
>
<
DataTemplate
>
<
listView:ListViewTemplateCell
>
<
listView:ListViewTemplateCell.View
>
<
Grid
Padding
=
"5"
>
<
Grid.RowDefinitions
>
<
RowDefinition
Height
=
"Auto"
/>
<
RowDefinition
Height
=
"Auto"
/>
</
Grid.RowDefinitions
>
<
Label
Grid.Row
=
"0"
Text
=
"{Binding SiteName}"
FontSize
=
"Large"
/>
<
Label
Grid.Row
=
"1"
Text
=
"{Binding SiteDetailText}"
/>
</
Grid
>
</
listView:ListViewTemplateCell.View
>
</
listView:ListViewTemplateCell
>
</
DataTemplate
>
</
telerikui:RadListView.ItemTemplate
>
<!-- this doesn't work -->
<
telerikui:RadListView.GroupDescriptors
>
<
listView:PropertyGroupDescriptor
PropertyName
=
"FarmName"
/>
</
telerikui:RadListView.GroupDescriptors
>
</
telerikui:RadListView
>
I get the collection of Site models from a JSON string, and sometimes the FarmName property is missing, meaning FarmName is null. When I run the application this exception is thrown;
03-23 12:08:52.176 I/MonoDroid( 4852): UNHANDLED EXCEPTION:
03-23 12:08:52.180 I/MonoDroid( 4852): System.ArgumentException: The default comparer works with elements that implement IComparable interface.
03-23 12:08:52.180 I/MonoDroid( 4852): at (wrapper managed-to-native) Java.Interop.NativeMethods:java_interop_jnienv_call_nonvirtual_void_method_a (intptr,intptr&,intptr,intptr,intptr,Java.Interop.JniArgumentValue*)
03-23 12:08:52.180 I/MonoDroid( 4852): at Java.Interop.JniEnvironment+InstanceMethods.CallNonvirtualVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x0008f] in /Users/builder/data/lanes/4009/9578cdcd/source/Java.Interop/src/Java.Interop/Java.Interop/JniEnvironment.g.cs:12079
03-23 12:08:52.180 I/MonoDroid( 4852): at Android.Runtime.JNIEnv.CallNonvirtualVoidMethod (System.IntPtr jobject, System.IntPtr jclass, System.IntPtr jmethod, Android.Runtime.JValue* parms) [0x00000] in /Users/builder/data/lanes/4009/9578cdcd/source/monodroid/src/Mono.Android/JNIEnv.g.cs:444
03-23 12:08:52.180 I/MonoDroid( 4852): at Com.Telerik.Widget.List.ListViewAdapter.set_Items (System.Collections.IList value) [0x0009d] in <4ab376ccf3e94543ba940e1beffd5307>:0
03-23 12:08:52.180 I/MonoDroid( 4852): at Telerik.XamarinForms.DataControlsRenderer.Android.ListViewDataSourceAdapterExtensions.SetSource (Com.Telerik.Widget.List.ListViewDataSourceAdapter adapter, System.Collections.IEnumerable source) [0x00007] in <0283f7990ca1485d8a9efc5b1581ce6f>:0
03-23 12:08:52.180 I/MonoDroid( 4852): at Telerik.XamarinForms.DataControlsRenderer.Android.ListViewAdapter.UpdateItemsSource (Telerik.XamarinForms.DataControls.RadListView sourceOwner, Com.Telerik.Widget.List.RadListView targetOwner) [0x00011] in <0283f7990ca1485d8a9efc5b1581ce6f>:0
03-23 12:08:52.180 I/MonoDroid( 4852): at Telerik.XamarinForms.DataControlsRenderer.Android.ListViewAdapter.UpdateCore (Telerik.XamarinForms.DataControls.RadListView sourceOwner, Com.Telerik.Widget.List.RadListView targetOwner, System.String propertyName) [0x0004b] in <0283f7990ca1485d8a9efc5b1581ce6f>:0
03-23 12:08:52.180 I/MonoDroid( 4852): at Telerik.XamarinForms.Common.FacadeAdapterBase`2[S,T].Update (System.Object sourceOwner, System.Object targetOwner, System.String propertyName, System.Object sourceOwnerRoot, System.Object targetOwnerRoot) [0x00000] in <41a54de86ddf4ac5b8f46f7114ddd5ec>:0
03-23 12:08:52.180 I/MonoDroid( 4852): at Telerik.XamarinForms.Common.XamarinToNativeControlExtensions.Update[T,K] (T nativeElement, K xfЕlement, System.String propertyName, System.Object sourceOwnerRoot, System.Object targetOwnerRoot) [0x0002b] in <41a54de86ddf4ac5b8f46f7114ddd5ec>:0
03-23 12:08:52.180 I/MonoDroid( 4852): at Telerik.XamarinForms.DataControlsRenderer.Android.ListViewRenderer.OnElementPropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs e) [0x00023] in <0283f7990ca1485d8a9efc5b1581ce6f>:0
03-23 12:08:52.180 I/MonoDroid( 4852): at (wrapper delegate-invoke) <Module>:invoke_void_object_PropertyChangedEventArgs (object,System.ComponentModel.PropertyChangedEventArgs)
03-23 12:08:52.180 I/MonoDroid( 4852): at Xamarin.Forms.BindableObject.OnPropertyChanged (System.String propertyName) [0x0000a] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\BindableObject.cs:137
03-23 12:08:52.180 I/MonoDroid( 4852): at Xamarin.Forms.Element.OnPropertyChanged (System.String propertyName) [0x00000] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\Element.cs:379
03-23 12:08:52.180 I/MonoDroid( 4852): at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindableObject+BindablePropertyContext context, System.Object value, System.Boolean currentlyApplying, Xamarin.Forms.BindableObject+SetValueFlags attributes, System.Boolean silent) [0x000f4] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\BindableObject.cs:581
03-23 12:08:52.180 I/MonoDroid( 4852): at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.BindableObject+SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes) [0x0014b] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\BindableObject.cs:378
03-23 12:08:52.180 I/MonoDroid( 4852): 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:173
03-23 12:08:52.180 I/MonoDroid( 4852): at Xamarin.Forms.BindingExpression.Apply (System.Boolean fromTarget) [0x0003e] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\BindingExpression.cs:55
03-23 12:08:52.180 I/MonoDroid( 4852): at Xamarin.Forms.BindingExpression+BindingExpressionPart.<PropertyChanged>b__47_0 () [0x00000] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\BindingExpression.cs:542
03-23 12:08:52.180 I/MonoDroid( 4852): at Java.Lang.Thread+RunnableImplementor.Run () [0x0000b] in /Users/builder/data/lanes/4009/9578cdcd/source/xamarin-android/src/Mono.Android/Java.Lang/Thread.cs:36
03-23 12:08:52.180 I/MonoDroid( 4852): at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00009] in /Users/builder/data/lanes/4009/9578cdcd/source/monodroid/src/Mono.Android/platforms/android-25/src/generated/Java.Lang.IRunnable.cs:81
03-23 12:08:52.180 I/MonoDroid( 4852): at (wrapper dynamic-method) System.Object:7de252d4-c417-4d4a-8229-509ea6b9512e (intptr,intptr)
The Fix
If I remove the <RadListView.GroupDescriptors> from the XAML this works fine...
Also, It works without crashing if I change the definition of the FarmName property to have a default value;
public
string
FarmName {
get
;
set
; } =
"No Farm"
Can we please have it so the List can handle these null values gracefully (empty string maybe)? Either that or show a clearer error message. I've spent 4 hours trying to get this grouping working, and until I stumbled across the stack trace for the IComparer exception I was struggling to figure out where to start.
Cheers