Debug.WriteLine not writing to Output window

Lance James 366 Reputation points

Created a Windows Form, Net 6, Visual Studio project.


using System.Diagnostics;  

foreach (var item in list)  

When running in Debug mode nothing prints to the Output window. I put a Break in the loop and the code does iterate through item.
Interesting to me is that if I put a break on


the red dot disappears when executing the program in Debug mode and I never land on the line. The code moves through it.

I checked and Output window is set to receive data.


Anything else I am forgetting to check?


An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
9,460 questions
0 comments No comments
{count} votes

Accepted answer
  1. Michael Taylor 41,811 Reputation points

    First question, are you compiling your code with the Debug configuration? If not then the call to Debug.WriteLine will be stripped out of the code at compilation. Note that this isn't the same as selecting the option to debug your program (F5).

    Secondly, check your compilation settings for the project. For a debug configuration the DEBUG symbol will be defined. Unless you mucked with the settings this should be default.

    Thirdly, you are debugging this project and it doesn't have any compilation errors right? It should be in bold in Solution Explorer, hence the startup project. Also if it has compiler errors and you simply press F5 then the IDE will offer to run the code anyway. If you select yes then it is running the last successfully built version, not the current version and this gets really confusing.

    If none of that helps then show the output window without the context menu pop up along with your project file contents (you can remove file itemgroups to keep it short).

0 additional answers

Sort by: Most helpful