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



The information in this article 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 Edition
  • Microsoft Visual Studio .NET (2003), Enterprise Architect Edition
  • Microsoft Visual Studio .NET (2002), Professional Edition
  • Microsoft Visual Studio .NET (2002), Enterprise Developer Edition
  • Microsoft Visual Studio .NET (2002), Enterprise Architect Edition
  • Microsoft Visual C# .NET (2002)
  • Microsoft Visual C# .NET (2003)

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("Debugger breaks here when the break point is set."); // Add a break point on this line.
	}
	Console.WriteLine("b = "+b);	

STATUS

This behavior is by design.

MORE INFORMATION

Steps to reproduce the behavior

  1. Start Visual Studio .NET or Visual Studio 2005.
  2. On the File menu, point to New, and then click Project.
  3. 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.
  4. 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("b = "+b); // The debugger breaks on this line.
  5. Add the break point on the close brace that was mentioned in the comments in the code.
  6. On the Debug menu, click Start to run the application.
  7. The debugger will break in the line that is next to the close brace that was mentioned in the "Symptoms" section of this article.

REFERENCES

For more information, visit the following Microsoft Developer Network (MSDN) Web site:

Modification Type:MajorLast Reviewed:2/28/2006
Keywords:kbvs2005swept kbvs2005applies kbIDEProject kbDebug kbVisIDDebugger kbprb KB833901 kbAudDeveloper