This question is locked. New answers and comments are not allowed.
Hi,
I decided to make a new thread for this issue:
I decided to make a new thread for this issue:
My GridView is a collection of IActivity which is an interface I made that 3 classes implement. This only happens when I try to adda new activity to the grid when it is sorted. When the Grid is not sorted, the activity is added to the grid. This is the error:
{System.InvalidOperationException: Failed to compare two elements in the array. ---> System.InvalidCastException: Unable to cast object of type 'FirstActivityViewModel' to type 'SecondActivityViewModel'.
at Telerik.Windows.Data.FuncExtensions.<>c__DisplayClass1`2.<ToUntypedFunc>b__0(Object item)
at Telerik.Windows.Data.FunctionComparer.Compare(Object x, Object y)
at System.Collections.Generic.ArraySortHelper`1.InternalBinarySearch(T[] array, Int32 index, Int32 length, T value, IComparer`1 comparer)
at System.Collections.Generic.ArraySortHelper`1.BinarySearch(T[] array, Int32 index, Int32 length, T value, IComparer`1 comparer)
--- End of inner exception stack trace ---
at System.Collections.Generic.ArraySortHelper`1.BinarySearch(T[] array, Int32 index, Int32 length, T value, IComparer`1 comparer)
at System.Array.BinarySearch[T](T[] array, Int32 index, Int32 length, T value, IComparer`1 comparer)
at System.Collections.Generic.List`1.BinarySearch(Int32 index, Int32 count, T item, IComparer`1 comparer)
at System.Collections.Generic.List`1.BinarySearch(T item, IComparer`1 comparer)
at Telerik.Windows.Data.KeyedCollection.IndexOf(Object value)
at Telerik.Windows.Data.QueryableCollectionView.InternalIndexOf(Object item)
at Telerik.Windows.Data.QueryableCollectionView.IndexOf(Object item)
at Telerik.Windows.Data.DataItemCollection.IndexOf(Object value)
at Telerik.Windows.Controls.DataControl.ItemCoerce(DependencyObject d, Object baseValue)
at Telerik.Windows.PropertyMetadata.DoCoercion(Func`3 areValuesEqual, DependencyObject d, DependencyProperty dp, CoerceValueCallback coerceCallback, Object defaultBaseValue, Boolean forceNewBaseValue, Boolean& isReentrantImplicitCoercion)
at Telerik.Windows.PropertyMetadata.PropertyChangeHook.OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object oldValue, Object newValue)
at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation)
at System.Windows.DependencyObject.RefreshExpression(DependencyProperty dp)
at System.Windows.Data.BindingExpression.SendDataToTarget()
at System.Windows.Data.BindingExpression.SourcePropertyChanged(PropertyPathListener sender, PropertyPathChangedEventArgs args)
at System.Windows.PropertyPathListener.RaisePropertyPathStepChanged(PropertyPathStep source)
at System.Windows.PropertyAccessPathStep.RaisePropertyPathStepChanged(PropertyListener source)
at System.Windows.CLRPropertyListener.SourcePropertyChanged(Object sender, PropertyChangedEventArgs args)
at System.Windows.Data.WeakPropertyChangedListener.PropertyChangedCallback(Object sender, PropertyChangedEventArgs args)
at System.ComponentModel.PropertyChangedEventHandler.Invoke(Object sender, PropertyChangedEventArgs e)
at GalaSoft.MvvmLight.ViewModelBase.RaisePropertyChanged(String propertyName)
at Telerik.Windows.Controls.RadSplitButton.ExecuteCommand()
at Telerik.Windows.Controls.RadSplitButton.OnClick()
at Telerik.Windows.Controls.RadSplitButton.ActionButton_Click(Object sender, RoutedEventArgs e)
at System.Windows.Controls.Primitives.ButtonBase.OnClick()
at System.Windows.Controls.Button.OnClick()
at Telerik.Windows.Controls.RadButton.OnClick()
at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
at System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e)
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)}
Is there a fix for this?
Thanks,
Jonathon
{System.InvalidOperationException: Failed to compare two elements in the array. ---> System.InvalidCastException: Unable to cast object of type 'FirstActivityViewModel' to type 'SecondActivityViewModel'.
at Telerik.Windows.Data.FuncExtensions.<>c__DisplayClass1`2.<ToUntypedFunc>b__0(Object item)
at Telerik.Windows.Data.FunctionComparer.Compare(Object x, Object y)
at System.Collections.Generic.ArraySortHelper`1.InternalBinarySearch(T[] array, Int32 index, Int32 length, T value, IComparer`1 comparer)
at System.Collections.Generic.ArraySortHelper`1.BinarySearch(T[] array, Int32 index, Int32 length, T value, IComparer`1 comparer)
--- End of inner exception stack trace ---
at System.Collections.Generic.ArraySortHelper`1.BinarySearch(T[] array, Int32 index, Int32 length, T value, IComparer`1 comparer)
at System.Array.BinarySearch[T](T[] array, Int32 index, Int32 length, T value, IComparer`1 comparer)
at System.Collections.Generic.List`1.BinarySearch(Int32 index, Int32 count, T item, IComparer`1 comparer)
at System.Collections.Generic.List`1.BinarySearch(T item, IComparer`1 comparer)
at Telerik.Windows.Data.KeyedCollection.IndexOf(Object value)
at Telerik.Windows.Data.QueryableCollectionView.InternalIndexOf(Object item)
at Telerik.Windows.Data.QueryableCollectionView.IndexOf(Object item)
at Telerik.Windows.Data.DataItemCollection.IndexOf(Object value)
at Telerik.Windows.Controls.DataControl.ItemCoerce(DependencyObject d, Object baseValue)
at Telerik.Windows.PropertyMetadata.DoCoercion(Func`3 areValuesEqual, DependencyObject d, DependencyProperty dp, CoerceValueCallback coerceCallback, Object defaultBaseValue, Boolean forceNewBaseValue, Boolean& isReentrantImplicitCoercion)
at Telerik.Windows.PropertyMetadata.PropertyChangeHook.OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object oldValue, Object newValue)
at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation)
at System.Windows.DependencyObject.RefreshExpression(DependencyProperty dp)
at System.Windows.Data.BindingExpression.SendDataToTarget()
at System.Windows.Data.BindingExpression.SourcePropertyChanged(PropertyPathListener sender, PropertyPathChangedEventArgs args)
at System.Windows.PropertyPathListener.RaisePropertyPathStepChanged(PropertyPathStep source)
at System.Windows.PropertyAccessPathStep.RaisePropertyPathStepChanged(PropertyListener source)
at System.Windows.CLRPropertyListener.SourcePropertyChanged(Object sender, PropertyChangedEventArgs args)
at System.Windows.Data.WeakPropertyChangedListener.PropertyChangedCallback(Object sender, PropertyChangedEventArgs args)
at System.ComponentModel.PropertyChangedEventHandler.Invoke(Object sender, PropertyChangedEventArgs e)
at GalaSoft.MvvmLight.ViewModelBase.RaisePropertyChanged(String propertyName)
at Telerik.Windows.Controls.RadSplitButton.ExecuteCommand()
at Telerik.Windows.Controls.RadSplitButton.OnClick()
at Telerik.Windows.Controls.RadSplitButton.ActionButton_Click(Object sender, RoutedEventArgs e)
at System.Windows.Controls.Primitives.ButtonBase.OnClick()
at System.Windows.Controls.Button.OnClick()
at Telerik.Windows.Controls.RadButton.OnClick()
at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
at System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e)
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)}
Is there a fix for this?
Thanks,
Jonathon