I was using .NET Reflector to disassemble code this morning and found an issue with VB.NET Select Case statements if they were originally compiled as Debug. If the case statements have comma delimited lists of strings for a single case, they will be improperly broken up during disassembly. This does not happen if the original VB.NET code is compiled as Release. I mocked this up in both VS2005 and VS2008. Both environments created code that decompiled incorrectly.
This is the code in question:
Public Shared Function DoSomething(ByVal szInput As String) As String
Dim szOutput As String
Select Case (szInput)
Case "aaa", "aab", "aac", "aad"
szOutput = "aa"
Case "aba", "abb", "abc", "abd"
szOutput = "ab"
Case Else
szOutput = "not found"
End Select
Return szOutput
End Function
Compiled as Debug and then disassembled:
Public Shared Function DoSomething(ByVal szInput As String) As String
Dim str3 As String = szInput
If (((str3 = "aaa") OrElse (str3 = "aab")) OrElse (str3 = "aac")) Then
End If
If (IIf((str3 = "aad"), 1, 0) <> 0) Then
Return "aa"
End If
If (((str3 = "aba") OrElse (str3 = "abb")) OrElse (str3 = "abc")) Then
End If
If (IIf((str3 = "abd"), 1, 0) <> 0) Then
Return "ab"
End If
Return "not found"
End Function
Compiled as Release and then disassembled:
Public Shared Function DoSomething(ByVal szInput As String) As String
Select Case szInput
Case "aaa", "aab", "aac", "aad"
Return "aa"
Case "aba", "abb", "abc", "abd"
Return "ab"
End Select
Return "not found"
End Function
I am using .NET Reflector version 6.1.0.11. For what it's worth, disassembling to C# results in the same (broken) logic.[/code]
This is the code in question: Compiled as Debug and then disassembled: Compiled as Release and then disassembled:
I am using .NET Reflector version 6.1.0.11. For what it's worth, disassembling to C# results in the same (broken) logic.[/code]