A
Amit Chaudhary
I have written the following code in VB.NET
______________________________________________________
Private Sub SetSortAttributes()
If RequestMode <> 2 Then
If dgInnerGrid.Columns.Count = 0 Then
dgInnerGrid.DisplayLayout.AllowSortingDefault =
AllowSorting.No
Else
If IsPersistedState Then
If dgInnerGrid.Rows.Count >= PersistedRecordNumber
AndAlso PersistedRecordNumber > -1 AndAlso RequestMode <> 0 Then
dgInnerGrid.DisplayLayout.ActiveRow =
dgInnerGrid.Rows(Me.PersistedRecordNumber)
End If
End If
Dim sorter As String = CStr(IIf(IsPersistedState AndAlso
(RequestMode = 3 OrElse RequestMode = 0), PersistedSortColumn,
SortColumn))
Dim order As String = CStr(IIf(IsPersistedState AndAlso
(RequestMode = 3 OrElse RequestMode = 0), PersistedSortOrder,
SortOrder))
If sorter.Length > 0 AndAlso order.Length > 0 Then
ClearSortIndicator()
If order.Equals(ASC_ORDER) Then
dgInnerGrid.Columns.FromKey(sorter).SortIndicator =
Infragistics.WebUI.UltraWebGrid.SortIndicator.Ascending
Else
dgInnerGrid.Columns.FromKey(sorter).SortIndicator =
Infragistics.WebUI.UltraWebGrid.SortIndicator.Descending
End If
End If
End If
End If
End Sub
It is working perfectly fine in DEBUG Mode.
But "Object reference not set to an instance of an object." exception
in RELEASE Mode.
When I decompile the above code using Reflector.
When code is compiled in Debug Mode then decompiled Output is:
______________________________________________________
Private Sub SetSortAttributes()
If (Me.RequestMode <> 2) Then
If (Me.dgInnerGrid.Columns.Count = 0) Then
Me.dgInnerGrid.DisplayLayout.AllowSortingDefault =
AllowSorting.No
Else
If (Me.IsPersistedState AndAlso
(((Me.dgInnerGrid.Rows.Count >= Me.PersistedRecordNumber) AndAlso
(Me.PersistedRecordNumber > -1)) AndAlso (Me.RequestMode <> 0))) Then
Me.dgInnerGrid.DisplayLayout.ActiveRow =
Me.dgInnerGrid.Rows.Item(Me.PersistedRecordNumber)
End If
Dim text2 As String =
StringType.FromObject(Interaction.IIf((Me.IsPersistedState AndAlso
((Me.RequestMode = 3) OrElse (Me.RequestMode = 0))),
Me.PersistedSortColumn, Me.SortColumn))
Dim text1 As String =
StringType.FromObject(Interaction.IIf((Me.IsPersistedState AndAlso
((Me.RequestMode = 3) OrElse (Me.RequestMode = 0))),
Me.PersistedSortOrder, Me.SortOrder))
If ((text2.Length > 0) AndAlso (text1.Length > 0))
Then
Me.ClearSortIndicator
If text1.Equals("ASC") Then
Me.dgInnerGrid.Columns.FromKey(text2).SortIndicator =
SortIndicator.Ascending
Else
Me.dgInnerGrid.Columns.FromKey(text2).SortIndicator =
SortIndicator.Descending
End If
End If
End If
End If
End Sub
When code is compiled in Release Mode then decompiled Output is:
______________________________________________________
Private Sub SetSortAttributes()
If (Me.RequestMode <> 2) Then
If (Me.dgInnerGrid.Columns.Count = 0) Then
Me.dgInnerGrid.DisplayLayout.AllowSortingDefault =
AllowSorting.No
Else
If ((Me.IsPersistedState AndAlso
(Me.dgInnerGrid.Rows.Count >= Me.PersistedRecordNumber)) AndAlso
((Me.PersistedRecordNumber > -1) AndAlso (Me.RequestMode <> 0))) Then
Me.dgInnerGrid.DisplayLayout.ActiveRow =
Me.dgInnerGrid.Rows.Item(Me.PersistedRecordNumber)
End If
Dim text2 As String =
StringType.FromObject(Interaction.IIf((Me.IsPersistedState AndAlso
((Me.RequestMode = 3) OrElse (Me.RequestMode = 0))),
Me.PersistedSortColumn, Me.SortColumn))
Dim text1 As String =
StringType.FromObject(Interaction.IIf((Me.IsPersistedState AndAlso
((Me.RequestMode = 3) OrElse (Me.RequestMode = 0))),
Me.PersistedSortOrder, Me.SortOrder))
If ((text2.Length > 0) AndAlso (text1.Length > 0))
Then
Me.ClearSortIndicator
If text1.Equals("ASC") Then
Me.dgInnerGrid.Columns.FromKey(text2).SortIndicator =
SortIndicator.Ascending
Else
Me.dgInnerGrid.Columns.FromKey(text2).SortIndicator =
SortIndicator.Descending
End If
End If
End If
End If
End Sub
______________________________________________________
The statement in Debug Mode:
If (Me.IsPersistedState AndAlso (((Me.dgInnerGrid.Rows.Count >=
Me.PersistedRecordNumber) AndAlso (Me.PersistedRecordNumber > -1))
AndAlso (Me.RequestMode <> 0))) Then
The statement in Release Mode:
If ((Me.IsPersistedState AndAlso (Me.dgInnerGrid.Rows.Count >=
Me.PersistedRecordNumber)) AndAlso ((Me.PersistedRecordNumber > -1)
AndAlso (Me.RequestMode <> 0))) Then
Is the root of the exception? I can implement the workaround.
But Is it possible for any Microsoft guys to confirm the problem.
-Amit
______________________________________________________
Private Sub SetSortAttributes()
If RequestMode <> 2 Then
If dgInnerGrid.Columns.Count = 0 Then
dgInnerGrid.DisplayLayout.AllowSortingDefault =
AllowSorting.No
Else
If IsPersistedState Then
If dgInnerGrid.Rows.Count >= PersistedRecordNumber
AndAlso PersistedRecordNumber > -1 AndAlso RequestMode <> 0 Then
dgInnerGrid.DisplayLayout.ActiveRow =
dgInnerGrid.Rows(Me.PersistedRecordNumber)
End If
End If
Dim sorter As String = CStr(IIf(IsPersistedState AndAlso
(RequestMode = 3 OrElse RequestMode = 0), PersistedSortColumn,
SortColumn))
Dim order As String = CStr(IIf(IsPersistedState AndAlso
(RequestMode = 3 OrElse RequestMode = 0), PersistedSortOrder,
SortOrder))
If sorter.Length > 0 AndAlso order.Length > 0 Then
ClearSortIndicator()
If order.Equals(ASC_ORDER) Then
dgInnerGrid.Columns.FromKey(sorter).SortIndicator =
Infragistics.WebUI.UltraWebGrid.SortIndicator.Ascending
Else
dgInnerGrid.Columns.FromKey(sorter).SortIndicator =
Infragistics.WebUI.UltraWebGrid.SortIndicator.Descending
End If
End If
End If
End If
End Sub
It is working perfectly fine in DEBUG Mode.
But "Object reference not set to an instance of an object." exception
in RELEASE Mode.
When I decompile the above code using Reflector.
When code is compiled in Debug Mode then decompiled Output is:
______________________________________________________
Private Sub SetSortAttributes()
If (Me.RequestMode <> 2) Then
If (Me.dgInnerGrid.Columns.Count = 0) Then
Me.dgInnerGrid.DisplayLayout.AllowSortingDefault =
AllowSorting.No
Else
If (Me.IsPersistedState AndAlso
(((Me.dgInnerGrid.Rows.Count >= Me.PersistedRecordNumber) AndAlso
(Me.PersistedRecordNumber > -1)) AndAlso (Me.RequestMode <> 0))) Then
Me.dgInnerGrid.DisplayLayout.ActiveRow =
Me.dgInnerGrid.Rows.Item(Me.PersistedRecordNumber)
End If
Dim text2 As String =
StringType.FromObject(Interaction.IIf((Me.IsPersistedState AndAlso
((Me.RequestMode = 3) OrElse (Me.RequestMode = 0))),
Me.PersistedSortColumn, Me.SortColumn))
Dim text1 As String =
StringType.FromObject(Interaction.IIf((Me.IsPersistedState AndAlso
((Me.RequestMode = 3) OrElse (Me.RequestMode = 0))),
Me.PersistedSortOrder, Me.SortOrder))
If ((text2.Length > 0) AndAlso (text1.Length > 0))
Then
Me.ClearSortIndicator
If text1.Equals("ASC") Then
Me.dgInnerGrid.Columns.FromKey(text2).SortIndicator =
SortIndicator.Ascending
Else
Me.dgInnerGrid.Columns.FromKey(text2).SortIndicator =
SortIndicator.Descending
End If
End If
End If
End If
End Sub
When code is compiled in Release Mode then decompiled Output is:
______________________________________________________
Private Sub SetSortAttributes()
If (Me.RequestMode <> 2) Then
If (Me.dgInnerGrid.Columns.Count = 0) Then
Me.dgInnerGrid.DisplayLayout.AllowSortingDefault =
AllowSorting.No
Else
If ((Me.IsPersistedState AndAlso
(Me.dgInnerGrid.Rows.Count >= Me.PersistedRecordNumber)) AndAlso
((Me.PersistedRecordNumber > -1) AndAlso (Me.RequestMode <> 0))) Then
Me.dgInnerGrid.DisplayLayout.ActiveRow =
Me.dgInnerGrid.Rows.Item(Me.PersistedRecordNumber)
End If
Dim text2 As String =
StringType.FromObject(Interaction.IIf((Me.IsPersistedState AndAlso
((Me.RequestMode = 3) OrElse (Me.RequestMode = 0))),
Me.PersistedSortColumn, Me.SortColumn))
Dim text1 As String =
StringType.FromObject(Interaction.IIf((Me.IsPersistedState AndAlso
((Me.RequestMode = 3) OrElse (Me.RequestMode = 0))),
Me.PersistedSortOrder, Me.SortOrder))
If ((text2.Length > 0) AndAlso (text1.Length > 0))
Then
Me.ClearSortIndicator
If text1.Equals("ASC") Then
Me.dgInnerGrid.Columns.FromKey(text2).SortIndicator =
SortIndicator.Ascending
Else
Me.dgInnerGrid.Columns.FromKey(text2).SortIndicator =
SortIndicator.Descending
End If
End If
End If
End If
End Sub
______________________________________________________
The statement in Debug Mode:
If (Me.IsPersistedState AndAlso (((Me.dgInnerGrid.Rows.Count >=
Me.PersistedRecordNumber) AndAlso (Me.PersistedRecordNumber > -1))
AndAlso (Me.RequestMode <> 0))) Then
The statement in Release Mode:
If ((Me.IsPersistedState AndAlso (Me.dgInnerGrid.Rows.Count >=
Me.PersistedRecordNumber)) AndAlso ((Me.PersistedRecordNumber > -1)
AndAlso (Me.RequestMode <> 0))) Then
Is the root of the exception? I can implement the workaround.
But Is it possible for any Microsoft guys to confirm the problem.
-Amit