We have our custom class for saving the grid configuration, i.e sorting/grouping/resizing/column order and we add Unloaded event on our grid like so:
public static void Persistence(/*params here*/)
grid.Unloaded += (sender, args) =>
{
var data = GenerateGridSettings(grid, whatToSave, column => column.UniqueName);
if (data != null)
// save settings goes here
};
}
Although this looks good and I as developer and the QA team do not get error messages, our customers get error messages, specifically "Object was not set to an instance of an object". The error output is this:
2020/09/03 09:36:17.259 29 - 17832 Client.Global.Dispatcher FATAL Object reference not set to an instance of an object.
at Controls.RadGridSupport.<>c.<Persistence>b__26_4(GridViewColumn column)
at Controls.RadGridSupport.GenerateGridSettings(RadGridView rgv, RadGridSettingSelection whatToSave, Func`2 mapColumnToName)
at Controls.RadGridSupport.<>c__DisplayClass26_0.<Persistence>b__1(Object sender, RoutedEventArgs args)
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.RaiseEvent(RoutedEventArgs e)
at System.Windows.BroadcastEventHelper.BroadcastEvent(DependencyObject root, RoutedEvent routedEvent)
at System.Windows.BroadcastEventHelper.BroadcastUnloadedEvent(Object root)
at MS.Internal.LoadedOrUnloadedOperation.DoWork()
at System.Windows.Media.MediaContext.FireLoadedPendingCallbacks()
at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
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)
As if the column in the lambda expression "column => column.UniqueName" gets deleted at some point before unloaded event.
Is this possible? Can the column be deleted before the unloaded event?