Potential race conditions causing ArgumentNullException from TreeListBox

Grids for WPF Forum

The latest build of this product (v25.1.4) was released 2 months ago, which was before this thread was created.
Posted 2 days ago by Amer KHAZNA DAR
Version: 24.1.4
Platform: .NET 9
Environment: Windows 11 (64-bit)
Avatar

Hello!

I'm occasionally getting unhandled ArgumentNullException, with source "ActiproSoftware.Grids.Wpf", crashing my application.

After some debugging, it seems to me that this happens when the RootItem becomes null (due to a binding in my case) while the TreeListBox is doing some other action.

I've noticed two types of callstacks when this happens, the first:

System.ArgumentNullException: Value cannot be null. (Parameter 'item')
   at ActiproSoftware.Windows.Controls.Grids.TreeListBox.CanSelect(TreeMultiSelectionKind kind, TreeNode treeNode, Boolean compareToActive)
   at ActiproSoftware.Windows.Controls.Grids.TreeListBox.OnSelectedItemPropertyValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
   at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
   at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
   at System.Windows.DependencyObject.InvalidateProperty(DependencyProperty dp, Boolean preserveCurrentValue)
   at System.Windows.Data.BindingExpression.TransferValue(Object newValue, Boolean isASubPropertyChange)
   at MS.Internal.Data.PropertyPathWorker.UpdateSourceValueState(Int32 k, ICollectionView collectionView, Object newValue, Boolean isASubPropertyChange)
   at System.Windows.DependentList.InvalidateDependents(DependencyObject source, DependencyPropertyChangedEventArgs sourceArgs)
   at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
   at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
   at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
   [Own code removed. It mentions the setter of a view model property with a two way binding to the "SelectedItem" of the TreeListBox]
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at ActiproSoftware.Windows.Controls.Grids.TreeListBox.<>c__DisplayClass73_0.<RequestApplyFilter>b__0()
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

The second:

System.ArgumentNullException: Value cannot be null. (Parameter 'item')
   at ActiproSoftware.Windows.Controls.Grids.TreeListBox.CanSelect(TreeMultiSelectionKind kind, TreeNode treeNode, Boolean compareToActive)
   at ActiproSoftware.Windows.Controls.Grids.TreeListBox.AddToSelection(TreeNode treeNode, Boolean append, Boolean updateAnchor)
   at ActiproSoftware.Windows.Controls.Grids.TreeListBox.UpdateAllTreeNodeVisibility()
   at ActiproSoftware.Windows.Controls.Grids.TreeListBox.<>c__DisplayClass73_0.<RequestApplyFilter>b__0()
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)


My item adapter overrides "bool GetIsSelectable(TreeListBox ownerControl, object item)" to return false if the item is null and, looking at the control's source code, I don't see what more I could do on my side to avoid those exceptions.

Note:
I'm using .NET 10, but the platoform version dropdown stops at .NET 9.
I also can't use the latest version of Actipro WPF controls at the moment as it's not currently available for use internally in my company. If this issue is fixed in that version, I can try to request for it to be made available.

[Modified 2 days ago]

Comments (1)

Posted 21 hours ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

Thank you for reporting this.  We are currently wrapping up the v26.1 codebase.  A big chunk of the work we're doing for it is making our entire WPF API support proper nullable checking.  The good news is that as part of the effort of upgrading Grids for nullables, we have already updated logic in this area, and it should not run into this issue.  We hope v26.1 will be ready to roll out in the coming weeks.

In the meantime, perhaps you could replace RootItem with a valid root item that has no children instead of nulling it out?

[Modified 21 hours ago]


Actipro Software Support

Add Comment

Please log in to a validated account to post comments.