[DevExpress Support Team: CLONED FROM T371645: An exception is thrown when a summary is being calculated]
If the expression assigned to the ViewProperty.Property property contains the AggregateOperand with the Avg aggregate type and the AggregatedExpression references a property of the Single type, the ViewProperty type is determined as Decimal. Attached is a test project reproducing the issue.
Steps to reproduce:
Run the attached project and notice the alert message that appears when the Form is loaded. Close the alert message using the "Ignore" button and add a summary item to the TestProperty column.
Actual results:
The InvalidCast exception with the "Specified cast is not valid" message is raised with the following call stack:
> DevExpress.Data.v15.2.dll!DevExpress.Data.Helpers.GenericDelegateHelper.UnboxingConversionCreator.Impl<float?>.Unbox(object arg) Line 394 + 0x17 bytes C#
DevExpress.Data.v15.2.dll!DevExpress.Data.Helpers.GenericDelegateHelper.InvalidCastVerboseLogger.Impl<object,float?>.LoggedCast(System.Func<object,float?> nakedCast, object arg, System.Func<string[]> exceptionAuxInfoGetter) Line 244 + 0x24 bytes C#
DevExpress.Data.v15.2.dll!DevExpress.Data.Helpers.GenericDelegateHelper.InvalidCastVerboseLogger.Impl<object,float?>.CreateLoggedCast.AnonymousMethod__8(object a) Line 236 + 0x6b bytes C#
DevExpress.Data.v15.2.dll!DevExpress.Data.Helpers.GenericDelegateHelper.ChainApplier.Impl<int,object,float?>.ApplyChain.AnonymousMethod__d(int a) Line 211 + 0x49 bytes C#
System.Core.dll!System.Linq.Enumerable.CombineSelectors<int,int,float?>.AnonymousMethod__0(int x) + 0x81 bytes
System.Core.dll!System.Linq.Enumerable.CombineSelectors<int,float?,float?>.AnonymousMethod__0(int x) + 0x64 bytes
System.Core.dll!System.Linq.Enumerable.CombineSelectors<int,float?,float?>.AnonymousMethod__0(int x) + 0x64 bytes
System.Core.dll!System.Linq.Enumerable.WhereSelectEnumerableIterator<int,float?>.MoveNext() + 0x11f bytes
System.Core.dll!System.Linq.Enumerable.Average(System.Collections.Generic.IEnumerable<float?> source) + 0x147 bytes
DevExpress.Data.v15.2.dll!DevExpress.Data.Helpers.SummaryValueExpressiveCalculator.DoTypedAverage(System.Collections.IEnumerable valuesEnumerable, System.Type valuesType, System.Func<string[]> exceptionAuxInfoGetter) Line 133 + 0xad bytes C#
DevExpress.Data.v15.2.dll!DevExpress.Data.Helpers.SummaryValueExpressiveCalculator.Calculate(DevExpress.Data.SummaryItemType summaryItemType, System.Collections.IEnumerable valuesEnumerable, System.Type valuesType, bool ignoreNulls, System.Collections.IComparer customComparer, System.Func<string[]> exceptionAuxInfoGetter) Line 71 + 0x11 bytes C#
DevExpress.Data.v15.2.dll!DevExpress.Data.DataController.CalcSummaryValue(DevExpress.Data.SummaryItem summaryItem, DevExpress.Data.SummaryItemType summaryType, bool ignoreNullValues, System.Type valueType, System.Collections.IEnumerable valuesEnumerable, System.Func<string[]> exceptionAuxInfoGetter, DevExpress.Data.GroupRowInfo groupRow) Line 312 + 0x6d bytes C#
DevExpress.Data.v15.2.dll!DevExpress.Data.DataController.CalcSummaryValue(DevExpress.Data.SummaryItem summaryItem, DevExpress.Data.GroupRowInfo groupRow) Line 307 + 0x95 bytes C#
DevExpress.Data.v15.2.dll!DevExpress.Data.DataController.CalcSummaryInfo(DevExpress.Data.GroupRowInfo groupRow, DevExpress.Data.SummaryItem summaryItem, ref bool validResult) Line 244 + 0x1d bytes C#
DevExpress.Data.v15.2.dll!DevExpress.Data.DataController.CalcTotalSummaryItem(DevExpress.Data.SummaryItem summary) Line 323 + 0x27 bytes C#
DevExpress.Data.v15.2.dll!DevExpress.Data.DataController.UpdateTotalSummary(System.Collections.Generic.List<DevExpress.Data.SummaryItem> changedItems) Line 3006 + 0x59 bytes C#
DevExpress.XtraGrid.v15.2.dll!DevExpress.XtraGrid.Views.Grid.GridView.SynchronizeSummary() Line 10124 C#
DevExpress.XtraGrid.v15.2.dll!DevExpress.XtraGrid.Views.Grid.GridView.OnSummaryCollectionChanged(object sender, System.ComponentModel.CollectionChangeEventArgs e) Line 7498 C#
DevExpress.XtraGrid.v15.2.dll!DevExpress.XtraGrid.Views.Grid.GridView.OnColumnSummaryCollectionChanged(DevExpress.XtraGrid.Columns.GridColumn column, System.ComponentModel.CollectionChangeEventArgs e) Line 6827 + 0x6b bytes C#
DevExpress.XtraGrid.v15.2.dll!DevExpress.XtraGrid.Columns.GridColumn.Summary_CollectionChanged(object sender, System.ComponentModel.CollectionChangeEventArgs e) Line 750 C#
DevExpress.XtraGrid.v15.2.dll!DevExpress.XtraGrid.GridSummaryItemCollection.OnItemChanged(System.ComponentModel.CollectionChangeEventArgs e) Line 137 + 0x35 bytes C#
DevExpress.XtraGrid.v15.2.dll!DevExpress.XtraGrid.GridSummaryItem.OnChanged() Line 165 C#
DevExpress.XtraGrid.v15.2.dll!DevExpress.XtraGrid.GridSummaryItem.SetSummary(DevExpress.Data.SummaryItemType summaryType, string displayFormat, System.IFormatProvider format) Line 212 + 0x45 bytes C#
DevExpress.XtraGrid.v15.2.dll!DevExpress.XtraGrid.Menu.GridViewFooterMenu.OnMenuItemClick(object sender, System.EventArgs e) Line 283 C#
DevExpress.Utils.v15.2.dll!DevExpress.Utils.Menu.DXMenuItem.OnClick() + 0x5b bytes
DevExpress.Utils.v15.2.dll!DevExpress.Utils.Menu.DXMenuCheckItem.OnClick() + 0x5c bytes
DevExpress.Utils.v15.2.dll!DevExpress.Utils.Menu.DXMenuItem.GenerateClickEvent() + 0x34 bytes
DevExpress.Utils.v15.2.dll!DevExpress.Utils.Menu.DXPopupStandardMenu.OnStandardMenuClick(object sender, System.EventArgs e) + 0xa3 bytes
System.Windows.Forms.dll!System.Windows.Forms.MenuItem.OnClick(System.EventArgs e) + 0x14c bytes
System.Windows.Forms.dll!System.Windows.Forms.MenuItem.MenuItemData.Execute() + 0x59 bytes
System.Windows.Forms.dll!System.Windows.Forms.Command.Invoke() + 0x8f bytes
System.Windows.Forms.dll!System.Windows.Forms.Command.DispatchID(int id) + 0x6f bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.WmCommand(ref System.Windows.Forms.Message m) + 0x74 bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m) + 0x4c8 bytes
DevExpress.XtraEditors.v15.2.dll!DevExpress.XtraEditors.Container.EditorContainer.WndProc(ref System.Windows.Forms.Message m) + 0x231 bytes
DevExpress.XtraGrid.v15.2.dll!DevExpress.XtraGrid.GridControl.WndProc(ref System.Windows.Forms.Message m) Line 2968 C#
System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) + 0x51 bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m) + 0x156 bytes
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DebuggableCallback(System.IntPtr hWnd, int msg, System.IntPtr wparam, System.IntPtr lparam) + 0x10d bytes
[Native to Managed Transition]
[Managed to Native Transition]
System.Windows.Forms.dll!System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(System.IntPtr dwComponentID, int reason, int pvLoopData) + 0x59e bytes
System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(int reason, System.Windows.Forms.ApplicationContext context) + 0x66e bytes
System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoop(int reason, System.Windows.Forms.ApplicationContext context) + 0x76 bytes
System.Windows.Forms.dll!System.Windows.Forms.Application.Run(System.Windows.Forms.Form mainForm) + 0x69 bytes
DxSample.exe!DxSample.Program.Main() Line 28 + 0x25 bytes C#
Expected results:
The property type should match the value type and no exceptions should be raised when adding a summary item to the GridView column.