Hello, we are updating an old .NET 3.5 WinForm application that used an old version of Infragistics .NET Advantage 2 to .NET 4.5 and Infragistics 4, and are occasionally getting a NullReferenceException at GetRowCalcIndex while running the app. Stack trace follows:
System.NullReferenceException: Object reference not set to an instance of an object. at Infragistics.Win.UltraWinGrid.RefUtils.GetRowCalcIndex(UltraGridRow row, FormulaRowIndexSource rowIndexType) at Infragistics.Win.UltraWinGrid.RefRowIterator.GetNextRow() at Infragistics.Win.UltraWinGrid.RefRowIterator.MoveNext() at Infragistics.Win.UltraWinGrid.RefRowIterator.MoveNext() at Infragistics.Win.UltraWinGrid.RefCellCollection.RefCellCollectionEnumerator.MoveNext() at Infragistics.Win.CalcEngine.RangeCalcInfo.EvaluateNextRow() at Infragistics.Win.CalcEngine.UltraCalcEngine.Evaluate(Int64 ticks) at Infragistics.Win.CalcEngine.UltraCalcEngine.Recalc(Int64 ticks, Boolean isStartOfRecalcOperation) at Infragistics.Win.UltraWinCalcManager.UltraCalcManager.ReCalcInternal(Int64 ticks) at Infragistics.Win.UltraWinCalcManager.UltraCalcManager.ReCalc(Int64 millis) at Infragistics.Win.UltraWinCalcManager.UltraCalcManager.ReCalcSynchronous() at Infragistics.Win.UltraWinCalcManager.UltraCalcManager.VerifyReCalc() at Infragistics.Win.UltraWinCalcManager.UltraCalcManager.DirtyCalc(IUltraCalcReference reference, ValueDirtiedAction action) at Infragistics.Win.UltraWinCalcManager.UltraCalcManager.Infragistics.Win.CalcEngine.IUltraCalcManager.RowsCollectionVisibilityChanged(IUltraCalcReference reference) at Infragistics.Win.UltraWinGrid.ViewStyleBase.OnAfterRowListCreated_ProcessBand(UltraGridBand band) at Infragistics.Win.UltraWinGrid.ViewStyleBase.OnAfterRowListCreated(RowScrollRegion rsr) at Infragistics.Win.UltraWinGrid.ViewStyleBase.RecreateRowList(RowScrollRegion rsr, Boolean syncWithCalcManager) at Infragistics.Win.UltraWinGrid.RowScrollRegion.RegenerateVisibleRows(Boolean resetScrollInfo) at Infragistics.Win.UltraWinGrid.RowScrollRegion.WillScrollbarBeShown(ScrollbarVisibility assumeColScrollbarsVisible) at Infragistics.Win.UltraWinGrid.ViewStyleBase.FitColumnsToWidth() at Infragistics.Win.UltraWinGrid.BandsCollection.CalculateBandMetrics(Int32 pass) at Infragistics.Win.UltraWinGrid.BandsCollection.CalculateBandMetrics() at Infragistics.Win.UltraWinGrid.ColScrollRegionsCollection.InitializeMetricsHelper() at Infragistics.Win.UltraWinGrid.ColScrollRegionsCollection.InitializeMetrics() at Infragistics.Win.UltraWinGrid.RowScrollRegion.RegenerateVisibleRows(Boolean resetScrollInfo) at Infragistics.Win.UltraWinGrid.RowScrollRegion.WillScrollbarBeShown(ScrollbarVisibility assumeColScrollbarsVisible) at Infragistics.Win.UltraWinGrid.RowScrollRegion.PositionScrollbar(Boolean resetScrollInfo) at Infragistics.Win.UltraWinGrid.ScrollRegionBase.SetOriginAndExtent(Int32 origin, Int32 extent) at Infragistics.Win.UltraWinGrid.RowScrollRegion.SetOriginAndExtent(Int32 origin, Int32 extent) at Infragistics.Win.UltraWinGrid.DataAreaUIElement.ResizeRowScrollRegions() at Infragistics.Win.UltraWinGrid.DataAreaUIElement.PositionChildElements() at Infragistics.Win.UIElement.VerifyChildElements(ControlUIElementBase controlElement, Boolean recursive) at Infragistics.Win.UltraWinGrid.DataAreaUIElement.VerifyChildElements(ControlUIElementBase controlElement, Boolean recursive) at Infragistics.Win.UltraWinGrid.DataAreaUIElement.set_Rect(Rectangle value) at Infragistics.Win.UltraWinGrid.UltraGridUIElement.PositionChildElements() at Infragistics.Win.UIElement.VerifyChildElements(ControlUIElementBase controlElement, Boolean recursive) at Infragistics.Win.UltraWinGrid.UltraGridUIElement.VerifyChildElements(ControlUIElementBase controlElement, Boolean recursive) at Infragistics.Win.UIElement.DrawHelper(Graphics graphics, Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode, Boolean clipText, Boolean forceDrawAsFocused, Boolean preventAlphaBlendGraphics) at Infragistics.Win.ControlUIElementBase.Draw(Graphics graphics, Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode, Size elementSize, Boolean preventAlphaBlendGraphics) at Infragistics.Win.ControlUIElementBase.Draw(Graphics graphics, Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode) at Infragistics.Win.UltraWinGrid.UltraGridUIElement.Draw(Graphics graphics, Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode) at Infragistics.Win.UltraControlBase.OnPaint(PaintEventArgs pe) at Infragistics.Win.UltraWinGrid.UltraGrid.OnPaint(PaintEventArgs pe) at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer) at System.Windows.Forms.Control.WmPaint(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) 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)
We have an Infragistics.Win.UltraWinGrid.UltraGrid with a .CalcManager.CalcSettings property of:
"count ( [//_orderGrid/Order/OrderNumber] )"
where _orderGrid is the UltraGrid, Order is the band, and OrderNumber one of the columns of the band.
I suspect it has something to do with the grid filter, as we can most often trigger the exception by quickly toggling the filter.
Hello Richard,
The scenario you are describing is not that simple – it involves WinGrid and WinCalcManager controls. Also, you said you have filters in your grid and you were able to reproduce this by quickly toggling the filters. To be able to look into this I will need to reproduce it at my sight. Therefore, I will need a small isolated sample project demonstrating this behavior. Can you try to isolate this in such sample and send it to us for further investigation?
One more thing. Looking into your post you said you had set CalcSettings property of WinCalcManager. Actually WinCalcManager, nor WinGrid, has such property. Did you mean SetCalcSettings method?
Looking forward to your reply and sample provided.
Thanks for the reply Milko. Can we send you an installer for a version of our app that shows the problem? We do have a recent Infragistics license, but it was issued to our senior engineer, not to me. Do we have access to an Infragistics .pdb file or source so we could debug this here?
The relevant CalcManager code in the .Designer.cs file is:
this._ultraCalcManager = new Infragistics.Win.UltraWinCalcManager.UltraCalcManager(this.components);this._ultraCalcManager.SetCalcSettings(this._ultraStatusBar, new Infragistics.Win.UltraWinCalcManager.CalcSettings("Test", null, "count ( [//_orderGrid/Order/OrderNumber] )", "Text", Infragistics.Win.UltraWinCalcManager.CalcErrorIconAlignment.Default, null));this._orderGrid.CalcManager = this._ultraCalcManager;
Can you think of anything we might be doing wrong that would cause a NullReferenceException? It seems strange that the SetCalcSettings control is the form status bar, not the grid.
Hi Richard,
I have tried to reproduce your scenario in small sample project. I did not receive any exceptions while was testing with my sample. Attached is my project for your reference.
Please run this sample at your side, filter the Status column, and let me know what the result of this test is.
If my sample does not show correctly what you are doing at your application feel free to modify it and to reproduce your issue. Then send it back to me for further investigation. Keep in mind if I am not able to reproduce this at my side there is not much I can do about it.
Also, please stick to this forum thread. Creating of several threads asking same question will not improve the time frame you get answers from us.
Looking forward to your reply about the result of the test with my sample.
Thanks Milko, that was very helpful. The example you provided is very similar to what is throwing the exception in our code, but of course does not throw an exception. I suspect it is something in our code, but what?
Our development manager downloaded the .PDB and source files for Infragistics WinForms and I built our application against that. Unfortunately it just shows a dialog box instead of breaking on the exception. I enclosed a screen shot of the dialog.
I am running our app in the Visual Studio 2015 debugger; how can I make it use the .PDB files instead of showing the dialog when an exception is thrown? I have unchecked “Just My Code”, enabled Just-In-Time debugging, and added the path to the .PDB files to Symbols from Options / Debugging.
It was not my intention to abuse the forum by creating a new thread; the new thread is for a different exception I got when trying to calculate the column sums manually instead of using a CalcManager. I would prefer to use a CalcManager instead of doing this myself.
You may force Visual Studio to break on all exceptions. This will help you find where exactly the code stops working. To do so open Exception Window in your Visual Studio (Debug -> Windows -> Exception Window) and check Common Language Runtime Exceptions check box (it should be checked, not in intermediate mode). The picture you have uploaded is not visible, so I am not sure what window you have seen. However, setting the Visual Studio to break on all errors should make it break at the line where exception was thrown.
Regarding PDB files what you wrote seems ok to me and this should work. If you need additional information about how to use external PDB files you may check this article in MSDN – “ Specify Symbol (.pdb) and Source Files in the Visual Studio Debugger ”.
Please, try to force Visual Studio to break on all exceptions and check what is the null value forcing your application to break.
Hello again Milko. Apologies for the delay in replying, I was pulled into another project.
I have enabled Visual Studio to break on all exceptions, and it is throwing the NullReferenceException in Infragistics.Win.UltraWinGrid.RefUtils.GetRow(). Unfortunately the debugger shows “Cannot obtain value of the local variable ...” for all symbols; but my guess is UltraWinGrid.RefRowIterator.rows is null as this is the only reference type in the call. I further assume that rows is set in Infragistics.Win.CalcEngine.RangeCalcInfo.
Another idea occurs to me; our form actually contains two grids, a Master and Detail grid, and it is possible for there to be no Detail records for a specific Master grid row. The calculation should only be done for the Master grid; we are defining the Master grid summary with code like:
var gridColumns = _masterGrid.DisplayLayout.Bands[0].Columns; UltraGridColumn col = gridColumns.Add("NonProcessedOrderCount"); col.DataType = typeof(int); col.DefaultCellValue = 0; col.Formula = "if(or([Status]=" + ((int)OrderStatus.Complete).ToString() + ", [Status]=" + ((int)OrderStatus.Released).ToString() + ")), 0, [Quantity])"; col.Hidden = true; var gridSummaries = _masterGrid.DisplayLayout.Bands[0].Summaries; SummarySettings printSummary = gridSummaries.Add( "PrintCount", "sum([NonProcessedOrderCount])", SummaryPosition.UseSummaryPositionColumn, gridColumns["Quantity"]);
Now _masterGrid is the Master grid, but could RangeCalcInfo somehow be called on the Detail grid? The Detail grid has a column reference to the corresponding Master grid key column in the form .Designer.cs file; a condensed example is like this:
_detailGridMasterReferenceColumn.Formula = "[../../ordernumber]"
Thank you for your feedback.
Yes, you are correct. The only reference type in Infragistics.Win.UltraWinGrid.RefUtils.GetRow() is the rows collection. Did you succeed to load the symbols? Are you able now to debug this and to put a break point in the above method?
If you are able to put a break point you will be able to find if the rows collection is null. Also, you will be able to find which grid is calling this method – your Master or your Details grid.
Regarding your Details grid column formula – [../../ordernumber]. This should try to get the column “ordernumber” of the parent band of the band of the column you are setting this formula to. Does your Details grid has several bands? If not, this should not work at all. If you need to refer a column in the Master grid you should use something like this:
_detailGridMasterReferenceColumn.Formula = "[//_masterGrid/BandName/ordernumber]";
Please try to put a break point in your application, if possible at all, and let me know on which grid you get the exception as well as if the rows collection is null.