Under Review
Last Updated: 21 Feb 2025 18:27 by Stephen
Stephen
Created on: 14 Feb 2025 19:50
Category: GridView
Type: Bug Report
3
RadGridView raises ArgumentOutOfRangeException with pixelWidth < 0 in call to RenderTargetBitmap constructor when adding a group descriptor

The following exception is raised when adding a ColumnGroupDescriptor to the GroupDescriptors property of a RadGridView. This bug is data specific and I've only been able to duplicate it with a large data set but the issue seems like it could be addressed without the actual data, given that the code causing the issue is apparently passing a pixelWidth < 0.

System.ArgumentOutOfRangeException: 'The parameter value must be greater than zero.
Parameter name: pixelWidth'

  PresentationCore.dll!System.Windows.Media.Imaging.RenderTargetBitmap.RenderTargetBitmap(int pixelWidth, int pixelHeight, double dpiX, double dpiY, System.Windows.Media.PixelFormat pixelFormat) Unknown
  Telerik.Windows.Controls.dll!Telerik.Windows.Controls.FrameworkElementToImageConverter.ToImage(System.Windows.FrameworkElement element) Unknown
  Telerik.Windows.Controls.GridView.dll!Telerik.Windows.Controls.GridView.GridViewGroupPanel.ConvertFrameworkElementToImage(System.Windows.FrameworkElement frameworkElement) Unknown
  Telerik.Windows.Controls.GridView.dll!Telerik.Windows.Controls.GridView.GridViewGroupPanel.GetEffectiveContentForDescriptor(Telerik.Windows.Data.IGroupDescriptor descriptor) Unknown
  Telerik.Windows.Controls.GridView.dll!Telerik.Windows.Controls.GridView.GridViewGroupPanel.PrepareContainerForItemOverride(System.Windows.DependencyObject element, object item) Unknown
  PresentationFramework.dll!System.Windows.Controls.ItemsControl.MS.Internal.Controls.IGeneratorHost.PrepareItemContainer(System.Windows.DependencyObject container, object item) Unknown
  PresentationFramework.dll!System.Windows.Controls.Panel.AddChildren(System.Windows.Controls.Primitives.GeneratorPosition pos, int itemCount) Unknown
  PresentationFramework.dll!System.Windows.Controls.Panel.OnItemsChangedInternal(object sender, System.Windows.Controls.Primitives.ItemsChangedEventArgs args) Unknown
  PresentationFramework.dll!System.Windows.Controls.Panel.OnItemsChanged(object sender, System.Windows.Controls.Primitives.ItemsChangedEventArgs args) Unknown
  PresentationFramework.dll!System.Windows.Controls.ItemContainerGenerator.OnItemAdded(object item, int index, System.Collections.Specialized.NotifyCollectionChangedEventArgs collectionChangedArgs) Unknown
  PresentationFramework.dll!System.Windows.Controls.ItemContainerGenerator.OnCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs args) Unknown
  WindowsBase.dll!System.Windows.WeakEventManager.ListenerList<System.Collections.Specialized.NotifyCollectionChangedEventArgs>.DeliverEvent(object sender, System.EventArgs e, System.Type managerType) Unknown
  WindowsBase.dll!System.Windows.WeakEventManager.DeliverEvent(object sender, System.EventArgs args) Unknown
  PresentationFramework.dll!System.Windows.Data.CollectionView.OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs args) Unknown
  WindowsBase.dll!System.Windows.WeakEventManager.ListenerList<System.Collections.Specialized.NotifyCollectionChangedEventArgs>.DeliverEvent(object sender, System.EventArgs e, System.Type managerType) Unknown
  WindowsBase.dll!System.Windows.WeakEventManager.DeliverEvent(object sender, System.EventArgs args) Unknown
  PresentationFramework.dll!System.Windows.Data.CollectionView.OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs args) Unknown
  PresentationFramework.dll!System.Windows.Data.ListCollectionView.ProcessCollectionChangedWithAdjustedIndex(System.Collections.Specialized.NotifyCollectionChangedEventArgs args, int adjustedOldIndex, int adjustedNewIndex) Unknown
  System.dll!System.Collections.ObjectModel.ObservableCollection<System.__Canon>.OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e) Unknown
  Telerik.Windows.Data.dll!Telerik.Windows.Data.ObservableItemCollection<Telerik.Windows.Data.IGroupDescriptor>.OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e) Unknown
  System.dll!System.Collections.ObjectModel.ObservableCollection<System.__Canon>.InsertItem(int index, System.__Canon item) Unknown
> Sage.Platform.Core.Wpf.dll!Sage.EstDataSource.Wpf.RadGridViewSerializer.DeserializeGroupDescriptors(Telerik.Windows.Controls.GridView.GridViewDataControl grid, Sage.Wpf.Utilities.GridViewSerializationInfo serializationInfo) Line 524 C#
  Sage.Platform.Core.Wpf.dll!Sage.EstDataSource.Wpf.RadGridViewSerializer.DeserializeGridInfo(Telerik.Windows.Controls.GridView.GridViewDataControl grid, System.Func<string, bool> isRenamableColumn, System.Xml.XmlReader reader, bool skipDeserializeGroups) Line 235 C#
  Sage.Platform.Core.Wpf.dll!Sage.EstDataSource.Wpf.RadGridViewSerializer.DeserializeGridSettings(Telerik.Windows.Controls.GridView.GridViewDataControl grid, System.Func<string, bool> isRenamableColumn, System.IO.Stream stream, bool skipDeserializeGroups) Line 199 C#
  Sage.Platform.Core.Wpf.dll!Sage.EstDataSource.Wpf.RadGridViewSerializer.DeserializeGridSettings(Telerik.Windows.Controls.GridView.GridViewDataControl grid, System.Func<string, bool> isRenamableColumn, System.IO.Stream stream) Line 168 C#
  Sage.Estimating.DataSource.Wpf.dll!Sage.EstDataSource.Wpf.ViewModel.EstimateDB.EstimateGridViewModel.DeserializeLayoutGridInfo(Telerik.Windows.Controls.RadGridView dataGrid, System.IO.MemoryStream stream) Line 122 C#
  Sage.Estimating.DataSource.Wpf.dll!Sage.EstDataSource.Wpf.ViewModel.EstimateDB.EstimateGridViewModel.DeserializeCurrentLayoutGridInfo(Telerik.Windows.Controls.RadGridView dataGrid, System.IO.MemoryStream defaultLayoutStream) Line 257 C#
  Sage.Estimating.DataSource.Wpf.dll!Sage.EstDataSource.Wpf.View.EstimateDB.EstimateGrid.ApplyCurrentLayoutToGrid() Line 210 C#
  Sage.Estimating.DataSource.Wpf.dll!Sage.EstDataSource.Wpf.View.EstimateDB.EstimateGrid.EstimateInfoGrid_Loaded(object sender, System.Windows.RoutedEventArgs e) Line 167 C#
  PresentationCore.dll!System.Windows.EventRoute.InvokeHandlersImpl(object source, System.Windows.RoutedEventArgs args, bool reRaised) Unknown
  PresentationCore.dll!System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject sender, System.Windows.RoutedEventArgs args) Unknown
  PresentationFramework.dll!System.Windows.BroadcastEventHelper.BroadcastEvent(System.Windows.DependencyObject root, System.Windows.RoutedEvent routedEvent) Unknown
  PresentationFramework.dll!System.Windows.BroadcastEventHelper.BroadcastLoadedEvent(object root) Unknown
  PresentationCore.dll!MS.Internal.LoadedOrUnloadedOperation.DoWork() Unknown
  PresentationCore.dll!System.Windows.Media.MediaContext.FireLoadedPendingCallbacks() Unknown
  PresentationCore.dll!System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks() Unknown
  PresentationCore.dll!System.Windows.Media.MediaContext.RenderMessageHandlerCore(object resizedCompositionTarget) Unknown
  PresentationCore.dll!System.Windows.Media.MediaContext.RenderMessageHandler(object resizedCompositionTarget) Unknown
  WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs) Unknown
  WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source, System.Delegate callback, object args, int numArgs, System.Delegate catchHandler) Unknown
  WindowsBase.dll!System.Windows.Threading.DispatcherOperation.InvokeImpl() Unknown
  WindowsBase.dll!MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(object obj) Unknown
  mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) Unknown
  mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) Unknown
  mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Unknown
  WindowsBase.dll!MS.Internal.CulturePreservingExecutionContext.Run(MS.Internal.CulturePreservingExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Unknown
  WindowsBase.dll!System.Windows.Threading.DispatcherOperation.Invoke() Unknown
  WindowsBase.dll!System.Windows.Threading.Dispatcher.ProcessQueue() Unknown
  WindowsBase.dll!System.Windows.Threading.Dispatcher.WndProcHook(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled) Unknown
  WindowsBase.dll!MS.Win32.HwndWrapper.WndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled) Unknown
  WindowsBase.dll!MS.Win32.HwndSubclass.DispatcherCallbackOperation(object o) Unknown
  WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs) Unknown
  WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source, System.Delegate callback, object args, int numArgs, System.Delegate catchHandler) Unknown
  WindowsBase.dll!System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority priority, System.TimeSpan timeout, System.Delegate method, object args, int numArgs) Unknown
  WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam) Unknown
  [Native to Managed Transition]
  [Managed to Native Transition]
  WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame frame) Unknown
  PresentationFramework.dll!System.Windows.Application.RunDispatcher(object ignore) Unknown
  PresentationFramework.dll!System.Windows.Application.RunInternal(System.Windows.Window window) Unknown
  Sage.EstManagementConsole.exe!Sage.EstManagementConsole.EstimatingManagementConsoleApp.Main() Unknown

2 comments
Stephen
Posted on: 21 Feb 2025 18:27

Thanks Martin, your pre-measure code prevents the exception.

 

Unfortunately I don't have a separate project to provide and attempting to duplicate the grid from our application into a separate project would be very costly + still need a large amount of data (which I can't give out) to duplicate it.

ADMIN
Martin Ivanov
Posted on: 21 Feb 2025 15:50

Hello Stephen,

I've tested this, but couldn't reproduce the problem. That said, can you send over a sample project recreating the problem?

In the meantime, it seems the issue occurs because the deserialized DisplayContent property of ColumnGroupDescriptor is a visual (a FrameworkElement), which at the specific moment seems to have its ActualWidth/ActualHeight evaluated to double.NaN or double.PositiveInfinity. This causes the RenderTargetBitmap constructor to throw the reported error.

To avoid this, you can modify your Sage.EstDataSource.Wpf.RadGridViewSerializer.DeserializeGroupDescriptors(Telerik.Windows.Controls.GridView.GridViewDataControl grid, System.Func<string, bool> isRenamableColumn, System.Xml.XmlReader reader, bool skipDeserializeGroups) method. Basically, when deserializing the DisplayContent property of the ColumnGroupDescriptor, you can check if it is a FrameworkElement and if so pre-measure it like this:

 if (deserializedDisplayContent is FrameworkElement deserializedElement)
 {
     var measureSize = new Size(100, 100);
     deserializedElement.Measure(measureSize);
     deserializedElement.Arrange(new Rect(measureSize));
     deserializedElement.InvalidateMeasure();
     deserializedElement.InvalidateArrange();
     deserializedElement.UpdateLayout();
 }

columnGroupDescriptor.DisplayContent = deserializedDisplayContent;

Can you try this and let me know if it helps?

Regards,
Martin Ivanov
Progress Telerik

Enjoyed our products? Share your experience on G2 and receive a $25 Amazon gift card for a limited time!