Hello,
I am using a XamDataGrid with a few calculated unbound fields. I am using 2012.1 build 2107. LabelClickAction is SortByMultipleFieldsTriState but I am clicking on only a single column header to cause the NullReferenceException. Initial sort description is Field "Group" with IsGroupBy="True". "Group" is an UnboundField that is Collapsed and there is a GroupByEvaluator and GroupByComparer. I had to make some changes to the GroupByEvaluator and GroupByComparer to work around a bug in the DataPresenterExcelExporter.Export.
Line 8181 of Infragistics.Windows.DataPresenter.Calculations.RefUtils.GetRecord throws the exception because records is NULL:MainRecordSparseArray arr = records.SparseArray as MainRecordSparseArray;
I will describe why records is NULL here. Look at the attached call tree text file for reference.Evaluate(long ticks) enters a while loop on line 1912 and calls EvaluteNextRow() on line 1914 in UltraCalcEngine\UltraCalcEngine.csEvaluteNextRow() calls MoveNext() on line 1731 in UltraCalcEngine\Utils.csthe first line of MoveNext() calls _recordIterator.MoveNext() on line 6144 in DataPresenterCalculationAdapter\References.cs_recordIterator._child is not NULL and _recordIterator._firstTime is true - do loop is entered at line 5868 in References.csscopeResolved is set to Any on line 5914, _childTuple.Name is equal to the Field I clicked on to sort by, _childTuple.Scope is Anythis.GetFirstRecord() is called on line 5944In GetFirstRecord(), _calcScope is FilteredSortedList, _records is a DataRecordCollection with _groupByField = NULL, _previousSortStatus = NotSorted, IsRootLevel = true, IsTopLevel = true, RecordsType = DataRecord_rootRef._utils.GetRecord( _records, 0, calcScope ) is called on line 5782in GetRecord, arr.GetItemAtVisibleIndex( calcIndex ) is called on line 8183, value of call is returned down call frame as value for GetFirstRecord() call on line 5944 of References.cs in RefRecordIterator.MoveNext()_record is set to return value and has ViewableChildRecords = collection with 0 records, HasChildData = false, HasChildren = false, ParentRecord = GroupByRecord with 95 items_child has field values: _child = null, _childTuple = (name of column with formula), _record = null, _tuple = (name of column I clicked on to sort)RefUtils.GetImmediateChildRecordsMatchingFieldLayout( _record, _child._fieldLayout ) is called on line 6047 of References.cschildRecords is set to dr.ChildRecords which is a ExpandableFieldRecordCollection with Count 0NULL is returned since the collection has no child records - return value of NULL is set to _childRecords on line 6047 of References.cs_child.InitRecordsCollection( childRecords ) is called on the next line 6048 - childRecords is NULLInitRecordsCollection sets _records field to childRecords (which is NULL). It then calls this.Reset() which sets _record to NULL and _firstTime to trueAfter it returns the while instruction is executed - while ( null != _record && null != _child && !_child.MoveNext( ) ); - _record is not null and _child is not null so _child.MoveNext() is calledIn _child.MoveNext(), _child is NULL, _firstTime is true, _tuple.Scope is Any, _childTuple.Name = (name of unbound field with formula)_record = this.GetFirstRecord( ); is called at line 5944_rootRef._utils.GetRecord( _records, 0, calcScope ) is called, from GetFirstRecord() with _records = null, _calcScope = FilteredSortedList on line 5789In GetRecord, which was called with null _records, this line generates an uncaught NullReferenceException: MainRecordSparseArray arr = records.SparseArray as MainRecordSparseArray;
I have attached a text file with the call tree when the exception is thrown along with line numbers since I downloaded the source and pdb's for the build. The exception occurs when attempting to call MoveNext() on an child collection which is empty. The _record field in the child collection is NULL. Evaluate(long ticks) calls EvaluteNextRow() which calls MoveNext() to get the first row of the data presenter. Now where this gets strange is the RefRecordIterator thinks that the first row has a child collection. The exception occurs because when evaluating a simple unbound field reference with a formula, it creates an empty child collection with a NULL collection pointer and then attempts to get the SparseArray from the NULL reference.
Let me know if there is any other information you need. The formula attempting to be calculated is a simple subtraction of an unbound bound field (with a binding path) from a bound field.
I am just checking if you require any further assistance on the matter.
Sincerely,
Krasimir
Developer Support Engineer
Infragistics
www.infragistics.com/support
Thank you for your reply. It seems that the sample application did not pass through. I am re-attaching the sample application.
Looking forward to hearing from you.
Please attach your application and I will try to modify to reproduce. I forgot to mention that the calculations are Synchronous.
Thank you for your post. I have been looking into the issue that you have described and I could not managed to reproduce it. I have created a sample application following your scenario and when I click on a LabelPresenter to sort a Field, no exception is occurring in the XamDataGrid. I have tested the sample application that I have created, using both the RTM and the 2107 build of version 12.1.
Would you please modify my sample application in order to demonstrates the issue that you are referring to, in order to be able to investigate what the reason for it might be?