Microsoft KB Archive/833901

= When you set a break point on the close brace of a code block, the Visual Studio .NET debugger breaks at a different point =

Article ID: 833901

Article Last Modified on 4/23/2007

-

APPLIES TO


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

-





SYMPTOMS
When a break point is set on the close brace of a block of code, at run time, the debugger in Microsoft Visual Studio .NET or in Microsoft Visual Studio 2005 breaks at the line that is next to the close brace when the code is executed.



WORKAROUND
Add a new statement before the close brace, and then add the break point on the new statement instead of on the closing brace.

For example, replace the code in the Main function with following code: int b = 9; if (b == 9 ) {       int a = new System.Random.Next; Console.WriteLine(&quot;Debugger breaks here when the break point is set.&quot;); // Add a break point on this line. }   Console.WriteLine(&quot;b = &quot;+b);



STATUS
This behavior is by design.



Steps to reproduce the behavior
 Start Visual Studio .NET or Visual Studio 2005. On the File menu, point to New, and then click Project. In the New Project dialog box, click Visual C# Projects under Project Types, and then click Console Application under Templates. By default, Class1.cs file is created.

Note In Visual Studio 2005, click Visual C#. By default, Program.cs file is created.  In the Class1.cs file, add the following code in the Main function: int b = 9; if (b == 9 ) {       int a = new System.Random.Next; } // Add a break point on this line. Console.WriteLine(&quot;b = &quot;+b); // The debugger breaks on this line.  Add the break point on the close brace that was mentioned in the comments in the code. On the Debug menu, click Start to run the application.</li> The debugger will break in the line that is next to the close brace that was mentioned in the &quot;Symptoms&quot; section of this article.</li></ol>

<div class="references_section">