Ticket T371645
Visible to All Users
Duplicate

An exception is thrown when a summary is being calculated

created 9 years ago

Hi !

We have our own report framework that uses a Detail View where the data is bind setting the GridControl.DataSource to a XPView that we build up with the target properties.
The values are updated correct in the Grid, however when we add a summary item to one of the columns, we get an InvalidCastException. Exactly the same code works fine in DevEx 14.2.11 so something is changed in the latest DevEx version. GridControl or GridView ?
Anything familiar ?

I am trying to debug your source code to see what is going wrong.

BR

/Stefan

Type: InvalidCastException
Message:
Unable to cast object '23,9114284515381' of type 'Double' from type 'Object' to type 'Nullable`1'. (Original Message: Specified cast is not valid.), (column Index: 4), (column Name: 'C9461'), (column Caption: 'C9461'), (column Type: System.Single), (column Unbound: False), (column UnboundExpression: ""), (PropertyDescriptor: DevExpress.Xpo.ViewPropertyDescriptor), (PropertyDescriptor Name: 'C9461'), (PropertyDescriptor PropertyType: System.Single), (PropertyDescriptor ComponentType:System.Object[]), (expectedReturnType: System.Nullable`1[[System.Single, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]) [Source:DevExpress.Data.v15.2]
Inner Exception InvalidCastException
Specified cast is not valid. [Source:DevExpress.Data.v15.2]
Stack Trace:
   at DevExpress.Data.Helpers.GenericDelegateHelper.InvalidCastVerboseLogger.Impl`2.LoggedCast(Func`2 nakedCast, A arg, Func`1 exceptionAuxInfoGetter)
   at DevExpress.Data.Helpers.GenericDelegateHelper.InvalidCastVerboseLogger.Impl`2.<>c__DisplayClass9.<CreateLoggedCast>b__8(A a)
   at DevExpress.Data.Helpers.GenericDelegateHelper.ChainApplier.Impl`3.<>c__DisplayClasse.<ApplyChain>b__d(A a)
   at System.Linq.Enumerable.<>c__DisplayClass7_0`3.<CombineSelectors>b__0(TSource x)
   at System.Linq.Enumerable.<>c__DisplayClass7_0`3.<CombineSelectors>b__0(TSource x)
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Linq.Enumerable.Average(IEnumerable`1 source)
   at DevExpress.Data.Helpers.SummaryValueExpressiveCalculator.DoTypedAverage(IEnumerable valuesEnumerable, Type valuesType, Func`1 exceptionAuxInfoGetter)
   at DevExpress.Data.Helpers.SummaryValueExpressiveCalculator.Calculate(SummaryItemType summaryItemType, IEnumerable valuesEnumerable, Type valuesType, Boolean ignoreNulls, IComparer customComparer, Func`1 exceptionAuxInfoGetter)
   at DevExpress.Data.DataController.CalcSummaryValue(SummaryItem summaryItem, SummaryItemType summaryType, Boolean ignoreNullValues, Type valueType, IEnumerable valuesEnumerable, Func`1 exceptionAuxInfoGetter, GroupRowInfo groupRow)
   at DevExpress.Data.DataController.CalcSummaryValue(SummaryItem summaryItem, GroupRowInfo groupRow)
   at DevExpress.Data.DataController.CalcSummaryInfo(GroupRowInfo groupRow, SummaryItem summaryItem, Boolean& validResult)
   at DevExpress.Data.DataController.CalcTotalSummaryItem(SummaryItem summary)
   at DevExpress.Data.DataController.UpdateTotalSummary(List`1 changedItems)
   at DevExpress.XtraGrid.Views.Grid.GridView.SynchronizeSummary()
   at DevExpress.XtraGrid.Views.Grid.GridView.OnSummaryCollectionChanged(Object sender, CollectionChangeEventArgs e)
   at DevExpress.XtraGrid.Views.Grid.GridView.OnColumnSummaryCollectionChanged(GridColumn column, CollectionChangeEventArgs e)
   at DevExpress.XtraGrid.Columns.GridColumn.Summary_CollectionChanged(Object sender, CollectionChangeEventArgs e)
   at DevExpress.XtraGrid.GridSummaryItemCollection.OnItemChanged(CollectionChangeEventArgs e)
   at DevExpress.XtraGrid.GridSummaryItem.OnChanged()
   at DevExpress.XtraGrid.GridSummaryItem.SetSummary(SummaryItemType summaryType, String displayFormat, IFormatProvider format)
   at DevExpress.XtraGrid.Menu.GridViewFooterMenu.OnMenuItemClick(Object sender, EventArgs e)
   at DevExpress.Utils.Menu.DXMenuItem.OnClick()
   at DevExpress.Utils.Menu.DXMenuCheckItem.OnClick()
   at DevExpress.XtraBars.Utils.DXPopupXtraMenu.OnBarMenuClick(Object sender, ItemClickEventArgs e)
   at DevExpress.XtraBars.BarItem.OnClick(BarItemLink link)
   at DevExpress.XtraBars.BarBaseButtonItem.OnClick(BarItemLink link)
   at DevExpress.XtraBars.BarButtonItem.OnClick(BarItemLink link)
   at DevExpress.XtraBars.BarItemLink.OnLinkClick()
   at DevExpress.XtraBars.BarButtonItemLink.OnLinkClick()
   at DevExpress.XtraBars.BarItemLink.OnLinkAction(BarLinkAction action, Object actionArgs)
   at DevExpress.XtraBars.BarButtonItemLink.OnLinkAction(BarLinkAction action, Object actionArgs)
   at DevExpress.XtraBars.BarItemLink.OnLinkActionCore(BarLinkAction action, Object actionArgs)
   at DevExpress.XtraBars.ViewInfo.BarSelectionInfo.ClickLink(BarItemLink link)
   at DevExpress.XtraBars.ViewInfo.BarSelectionInfo.UnPressLink(BarItemLink link)
   at DevExpress.XtraBars.Controls.CustomLinksControl.OnMouseUp(MouseEventArgs e)
   at DevExpress.XtraBars.Controls.CustomPopupBarControl.OnMouseUp(MouseEventArgs e)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at DevExpress.XtraBars.Controls.CustomControl.WndProc(Message& msg)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Show previous comments (5)
SR SR
Stefan Ragnarsson 9 years ago

    It's the alternative with PropertyB we use and TotalYield is of type float so it's strange that it doesn't work then !?
    After debugging I found out that the SummaryItem.ColumnInfo.Type is Single so that is correct. The problem is in the DataController.cs, CalcSummaryValue(), where it should get the value on line 2380.

    C#
    [ReportItem(Aggregate = Aggregate.Sum)] [DbType("real")] public float TotalYield { get { return _totalYield; } set { SetPropertyValue<float>(ColumnTotalYield, ref _totalYield, value); } }

    How does it work for enums, then you have most likely an int type in the database so it need to be casted to the enum type in the GridColumn ?
    And as I wrote before, it works in 14.2 because that's the version we have in the current release version.
    Since the value is shown correct in the GridColumn it's only an issue with the calculation of the SummaryItem which somehow is changed in the latest version.

    Chan ging the type of the property will have a big impact on the legacy code so that is not a way forward. For us this is not good that we face these kidn of breaking changes when upgrading the Dev Express version.

    DevExpress Support Team 9 years ago

      If the TotalYield property type is float, then your code is correct and you do not need to change SevenDayAverage property type. In this situation, there indeed must be some kind of change in our code, which caused the exception. Let me research this issue further and discus it with our R&D team. Perhaps, we will need additional details about the error. I will get back to you when we find a solution of if we have any questions.

      DevExpress Support Team 9 years ago

        We have determined the conditions under which this exception might occur and our developers are going to fix this issue. For this purpose, I have created a separate ticket on your behalf that describes the issue in detail: XPView might return value of the type different than the property type if the AggregateOperand is used in the expression. The issue that you described in this ticket is most likely related to that issue and will be resolved as well. Let's wait when our developers finish their research.

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.