Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
85
NullReferenceException if FieldSortDescription is set to non-existing field
posted

After changing the name of a property a XamDataGrid field is bound to (see 1st change below), we got a NullReferenceException whenever resorting was done by the user by clicking on the column headers. After investigating some time (including looking into your ClearNonGroupByFields method using ILSpy) we detected that we had overlooked that we also have a sort description referring to that property. After changing that as well (see 2nd change below), the problem doesn´t arise anymore.

We initially changed this
<igDataPresenter:Field Name="Name" Label="Name" Width="40*">
to
<igDataPresenter:Field Name="Caption" Label="Name" Width="40*">

We then also changed this
<igDataPresenter:FieldSortDescription Direction="Ascending" FieldName="Name"/>
to
<igDataPresenter:FieldSortDescription Direction="Ascending" FieldName="Caption"/>

The exception doesn´t always arise but only if resorting is done while grouping is used. If the column is sorted without grouping first, it afterwards can be successfully sorted again while grouping is used. As we have solved our problem, this issue is not urgent. But, in our opinion, you should improve your error handling here.

The error arises with versions 2012.1 and 2014.2 with an identical stack trace (except the version number, of course):

System.NullReferenceException was unhandled
  HResult=-2147467261
  Message=Object reference not set to an instance of an object.
  Source=InfragisticsWPF4.DataPresenter.v12.1
  StackTrace:
       at Infragistics.Windows.DataPresenter.FieldSortDescriptionCollection.ClearNonGroupByFields()
       at Infragistics.Windows.DataPresenter.SortingAction.ProcessSortClickAction(FieldLayout fl, DataPresenterBase dp, FieldSortDescriptionCollection sortedFields)
       at Infragistics.Windows.DataPresenter.SortingAction.Perform(Object context)
       at Infragistics.Windows.Helpers.ActionHistory.PerformActionHelper(Object actionContext, ActionBase action, ActionsCollection undoList)
       at Infragistics.Windows.Helpers.ActionHistory.PerformAction(ActionBase action, Object actionContext)
       at Infragistics.Windows.DataPresenter.DataPresenterHistory.PerformAction(ActionBase action, Object context)
       at Infragistics.Windows.DataPresenter.Field.PerformLabelClickAction(Boolean isInGroupByArea)
       at Infragistics.Windows.DataPresenter.LabelPresenter.ProcessMouseLeftButtonUpHelper(MouseButtonEventArgs eventArgs, Boolean dragStarted)
       at Infragistics.Windows.DataPresenter.LabelPresenter.OnMouseLeftButtonUp(MouseButtonEventArgs e)
       at System.Windows.UIElement.OnMouseLeftButtonUpThunk(Object sender, MouseButtonEventArgs e)
       at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
       at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
       at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
       at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
       at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)
       at System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e)
       at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
       at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
       at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
       at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
       at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
       at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
       at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
       at System.Windows.Input.InputManager.ProcessStagingArea()
       at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
       at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
       at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
       at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
       at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
       at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
       at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
       at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
       at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
       at System.Windows.Threading.Dispatcher.Run()
       at System.Windows.Application.RunDispatcher(Object ignore)
       at System.Windows.Application.RunInternal(Window window)
       at System.Windows.Application.Run(Window window)
       at System.Windows.Application.Run()
       at BCI.Toccata.TubesWizard.StandaloneHost.App.Main() in c:\...\App.g.cs:line 50