Debug.WriteLine not writing to Output window

Lance James 371 Reputation points
2022-03-29T14:26:57.613+00:00

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

Added

using System.Diagnostics;  


foreach (var item in list)  
       Debug.WriteLine(item);  

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

Debug.WriteLine(item);  

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.

187907-image.png

Anything else I am forgetting to check?

Regards,
Lance

C#
C#
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.
10,927 questions
0 comments No comments
{count} votes

Accepted answer
  1. Michael Taylor 54,316 Reputation points
    2022-03-29T15:07:17.227+00:00

    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

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.