BUG: The if and else blocks of code unexpectedly execute in Visual Studio .NET 2002 (811324)



The information in this article applies to:

  • Microsoft Visual Studio .NET (2002), Enterprise Architect Edition
  • Microsoft Visual Studio .NET (2002), Academic Edition
  • Microsoft Visual Studio .NET (2002), Enterprise Developer Edition
  • Microsoft Visual Studio .NET (2002), Professional Edition
  • Microsoft Visual C# .NET (2002)

SYMPTOMS

Both the if and else blocks of code execute unexpectedly in an if-else statement when you create a Microsoft Visual C# .NET Console Application project in Microsoft Visual Studio .NET 2002.

CAUSE

This behavior occurs when the if-else statement is inside a try-catch block, and the finally block is empty.

WORKAROUND

To work around this issue, add a dummy statement in the finally block.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section. This problem was corrected in Microsoft Visual Studio .NET 2003.

MORE INFORMATION

Steps to reproduce the behavior

  1. In Visual Studio .NET 2002, create a Visual C# .NET Console Application project.
  2. Replace the code in Class1 with the following code.
    class Test { 
    		public static void Main() { 
    			object o = "test"; 
    			if (o is string) { 
    				try { 
    					Console.WriteLine("Test"); 
    				}
    				finally { 
    					//Console.WriteLine("Finally."); 
    				} 
    			} 
    			else { 
    				Console.WriteLine("Shouldn't get here."); 
    			} 
    			Console.ReadLine();
    		} 
    	} 
    

Modification Type:MinorLast Reviewed:8/16/2005
Keywords:kbvs2002sp1sweep kbCompiler kbbug KB811324 kbAudDeveloper kbAudITPRO