2

All of a sudden my Console.WriteLine isn't displaying anything anymore in the "Output" window. Debug.WriteLine does work though. I already checked with right-click on the "Output" window that all messages are still checked. I also went through the settings but couldn't find anything.

I ran out of idea's, does anyone have an idea on how to solve this?

The Cookies Dog
  • 1,915
  • 2
  • 22
  • 38

3 Answers3

3

Getting output from Console.Write/Line() to appear in the VS Output window is a non-trivial feature. it requires debugging with the "Visual Studio Hosting Process". You'll see it back in both your build directory and TaskMgr.exe's Processes tab, it has the same name as your project but ends with "vshost.exe".

A fair amount of invisible magic happens inside the hosting process. It is a custom host for the CLR that gives the CLR different behavior from the one you normally run with. It is very poorly documented, the primary reason for its existence appears to be related to security. But one goody it takes care of is being able to redirect output written with Console.Write to the Output window.

Project + Properties, Debug tab, verify that the "Enable the Visual Studio hosting process" option is still ticked.

This is otherwise perhaps a fortunate mishap. You really ought to use Debug.Print() or Debug.Write/Line() in your code to generate diagnostic strings. It uses an entirely different way to generate output, one that doesn't depend on the hosting process. It uses the default TraceListener, one that talks to the debugger directly. The underlying winapi call is OutputDebugString(). The best features of the Debug class is that the calls you make in your code are automatically removed when you build the Release version of your program. So they don't take any overhead anymore, not the case for Console.Write. And that you can reconfigure trace listeners to generate output to, for example, a file.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • He wrote in the comments above that `Console.WriteLine` doesn't appear in a real console as well. That, at least, should work without any VS magic. – JeffRSon Jun 08 '13 at 11:03
  • He doesn't have a "real console" in a WPF app. This question was asked in a somewhat clumsy way, also the reason it is getting closed as a dup I'd guess. As far as I can tell it is not a dup. – Hans Passant Jun 08 '13 at 12:19
  • Thanks, that was also checked. I just found out it's working again after disabling all plugins and enabling them again. No idea what happened but it fixed it. Your information is interesting though, I'll think about using Debug.WriteLine the next time :) – The Cookies Dog Jun 08 '13 at 13:40
0

I experienced same issue today, and resolved it. I checked many posts but did not help me. the root reason is you have used different files, which has same void Main() in different classes. When having two files with common function named main(), it will not work. System seems using only the default one called program class.

What you can do is to move the code under program.cs file (if you use C#), then it will be OK in the new window.

xav
  • 5,452
  • 7
  • 48
  • 57
joe
  • 1
0

Following will allow you to see both types of "console" messages:

  1. Paste the following two tests into your code so it runs both lines. These are tests for the output window:

     System.Console.WriteLine($"hello console!");
    
     System.Diagnostics.Debug.WriteLine($"hello debugger!");
    
  2. In Visual Studio choose VIEW > OUTPUT. You will see the results above in this output window after changing two settings below.

  3. When NOT DEBUGGING, in the OUTPUT window at the top under "Show Output From" choose: "YourProjectName - ASP.NET CORE Web Server". Run your code. You should see the "Console" text above.

  4. When DEBUGGING, in the OUTPUT window at the top under "Show Output From" choose: "Debugger". Run your code in debug mode. You should see the "Debug" text above.

Stokely
  • 12,444
  • 2
  • 35
  • 23