473,503 Members | 10,012 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Incorrect behavior of IIf in VB.NET (.NET Framework 1.1 SP1)

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.Asce nding
Else
dgInnerGrid.Columns.FromKey(sorter).SortIndicator =
Infragistics.WebUI.UltraWebGrid.SortIndicator.Desc ending
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.IsPersis tedState AndAlso
((Me.RequestMode = 3) OrElse (Me.RequestMode = 0))),
Me.PersistedSortColumn, Me.SortColumn))
Dim text1 As String =
StringType.FromObject(Interaction.IIf((Me.IsPersis tedState 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).SortIndicato r =
SortIndicator.Ascending
Else

Me.dgInnerGrid.Columns.FromKey(text2).SortIndicato r =
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.IsPersis tedState AndAlso
((Me.RequestMode = 3) OrElse (Me.RequestMode = 0))),
Me.PersistedSortColumn, Me.SortColumn))
Dim text1 As String =
StringType.FromObject(Interaction.IIf((Me.IsPersis tedState 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).SortIndicato r =
SortIndicator.Ascending
Else

Me.dgInnerGrid.Columns.FromKey(text2).SortIndicato r =
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

Aug 22 '06 #1
2 2736
Amit Chaudhary wrote:
Dim sorter As String = CStr(IIf(IsPersistedState AndAlso
(RequestMode = 3 OrElse RequestMode = 0), PersistedSortColumn,
SortColumn))
OK, it /could/ be a Bug but, IMHO, the way you've coded this feels wrong.

IIf /always/ evaluates all three of its arguments, regardless of the
outcome of the first.
AndAlso and OrElse are /shortcut/ operators, that drop-out as soon as
they see something they don't like.

It just feels to me like the two shouldn't be mixed.

I would suggest expanding them into full-blown If's:

Dim sorter As String = CStr( SortColumn )
If IsPersistedState _
AndAlso (RequestMode = 3 OrElse RequestMode = 0) _
Then
sorter = CStr( PersistedSortColumn )
End If

HTH,
Phill W.
Aug 22 '06 #2
IIf is not suited to direct logic flow - it is just a function and as such
all arguments are always fully evaluated.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
C# Code Metrics: Quick metrics for C#
"Amit Chaudhary" wrote:
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.Asce nding
Else
dgInnerGrid.Columns.FromKey(sorter).SortIndicator =
Infragistics.WebUI.UltraWebGrid.SortIndicator.Desc ending
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.IsPersis tedState AndAlso
((Me.RequestMode = 3) OrElse (Me.RequestMode = 0))),
Me.PersistedSortColumn, Me.SortColumn))
Dim text1 As String =
StringType.FromObject(Interaction.IIf((Me.IsPersis tedState 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).SortIndicato r =
SortIndicator.Ascending
Else

Me.dgInnerGrid.Columns.FromKey(text2).SortIndicato r =
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.IsPersis tedState AndAlso
((Me.RequestMode = 3) OrElse (Me.RequestMode = 0))),
Me.PersistedSortColumn, Me.SortColumn))
Dim text1 As String =
StringType.FromObject(Interaction.IIf((Me.IsPersis tedState 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).SortIndicato r =
SortIndicator.Ascending
Else

Me.dgInnerGrid.Columns.FromKey(text2).SortIndicato r =
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

Aug 22 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
853
by: DerekP | last post by:
I tried to install this SP1 but got the following message quote INFO 9002. ...Net Framwork SP1 (KB867460) cannot be installed because you have one or more hot fixes installed. Remove them and try...
0
450
by: georgel | last post by:
:shock: SmartNav.js problem solved for now... After some research I've concluded that replacing my old SmartNav.js file for the one included in the sp1 release remedies my issue of the 404...
0
1039
by: ThomasD | last post by:
Hi, we are shipping the .Net Framework with our Application. For a correct installation we need SP1 and the language pack. The problem is, that it take 12-15 minutes on an AMD Athlon XP+ 2,6...
1
1554
by: JimM | last post by:
How do i know if my Windows 2000 workstations and servers and Windows 2003 servers have SP1.1 installed? Thanks.
9
2983
by: AnandaSim | last post by:
Hi All, I've had Access 97, 2000 connections to the corporate Oracle database for a few years now - but seldom use it. When I did use it years ago, performance was not fast but the features were...
3
1452
by: Lew Burrus | last post by:
Hello, I just installed sp2 for XP (on my development server), and tested my application: worked fine. Then installed sp1 for the 1.1 framework (as urged by Windows Update) and now this: the...
3
1504
by: Arpan | last post by:
I have been trying to install .NET Framework SP1 in my system but am unable to do so. The 10.2 MB SP gets downloaded successfully after which the installation starts by itself from within the browser...
6
975
by: DraguVaso | last post by:
Hi, I guess it's always a good thing to install a SP. So I would like to install the Framework 1.1 SP1 to my development-pc, and also on my client's pc's. Although, I don't knwo if this would...
2
1232
by: AshokG | last post by:
Hi, In search of the differences between struct and class I found this MSDN Doc on Boxed Value Types: http://msdn2.microsoft.com/en-us/library/f08s4k28(VS.90).aspx The output is specified...
0
778
by: =?Utf-8?B?VW1lc2huYXRo?= | last post by:
I am using framework 2.0 and and my whole application wsa working fine. After installing framework SP1 all my java script validation are going exception since my AXD file is not rendering Please...
0
7194
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7070
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7267
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7316
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6976
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5566
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
372
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.