Microsoft KB Archive/811324

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

Article ID: 811324

Article Last Modified on 8/16/2005

-

APPLIES TO


 * Microsoft Visual Studio .NET 2002 Enterprise Architect
 * Microsoft Visual Studio .NET 2002 Academic Edition
 * Microsoft Visual Studio .NET 2002 Enterprise Developer
 * Microsoft Visual Studio .NET 2002 Professional Edition
 * Microsoft Visual C# .NET 2002 Standard Edition

-





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 &quot;Applies to&quot; section. This problem was corrected in Microsoft Visual Studio .NET 2003.



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

Keywords: kbbug kbcompiler kbvs2002sp1sweep KB811324

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.