question

JayJaeger-5755 avatar image
3 Votes"
JayJaeger-5755 asked HemendrGupta-2084 answered

VS 2019 Console.Writeline - Output not present in Output window

So, I am used to using Console.Writeline during development to generate debugging output (and then remove them and comment them out when no longer needed). My app is a C# Windows Forms App (not a WPF app). But the output is simply not appearing in the Output window (Show output from: Debug) where I was expecting it (and where I see it in VS 2017. What might I have overlooked? (I created a new little app from the template just as a test - and it doesn't show up on that one, either).

vs-generalvs-debugging
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Try using Debug.WriteLine instead.

1 Vote 1 ·

After adding System.Diagnostics that output does show up - but in the Immediate Window.

Question is, why doesn't the original way work? No exception - no nothing.

0 Votes 0 ·
HemendrGupta-2084 avatar image
0 Votes"
HemendrGupta-2084 answered

If you are using same methods on console that are available in Debug Class like console.WriteLine() then there is a hack in .Net Core where you can add below line

global using Console = System.Diagnostics.Debug;

as the first line of program.cs. Please remove Console.Readline() or use System.Console.ReadLine(); to halt the screen.

Now all your console.Witeline output will be executed as debug.WriteLine and console output visible in Output window.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

MarcusM-9057 avatar image
0 Votes"
MarcusM-9057 answered JayJaeger-5755 commented

what is the output-output window? Where can I find it?

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I presume that the previous poster meant "output window".

0 Votes 0 ·
Com-3005 avatar image
0 Votes"
Com-3005 answered Com-3005 published

Had the same problem. I guess it has been set after an update. You have to rightclick into the output-output window and activate "program output" and everything is back :-)

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

JayJaeger-5755 avatar image
1 Vote"
JayJaeger-5755 answered

Reported to day, in a thread what was first opened on this same issue on October 26, 2020:

https://developercommunity.visualstudio.com/t/VS2019-ConsoleWriteline-in-output-windo/1233073

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

JayJaeger-5755 avatar image
1 Vote"
JayJaeger-5755 answered JayJaeger-5755 edited

I have several projects in VS 2017 where Console.WriteLine() works the way I expected. In VS 2019, it does not work. I will report it as a problem. The VS 2019 application template I used was "Windows Forms App (.NET)" [as opposed to Windows Forms App (.NET Framework) or WPF App templates].

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

JayJaeger-5755 avatar image
0 Votes"
JayJaeger-5755 answered TianyuSun-MSFT edited

When I changed my message from Console.WriteLine() t Debug.WriteLine(), yes, the message did appear in the Output window, so this was NOT a matter of the code not reaching that point. The messages from Console.WriteLine() are not appearing. This worked fine in VS 2017 (in a different application. I even made a dummy application (much like what you have above) and put a Console.Writeline() right at the beginning after InitializeComponent, and the output from Debug.WriteLine() is there, but not Console.WriteLine().

public Form1()
{
InitializeComponent();

         Debug.WriteLine("Hello Debug!");
         Console.WriteLine("Hello Console!");

     }

Results in:

'WindowsFormsApp1.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.12\System.ComponentModel.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.

Hello Debug!

'WindowsFormsApp1.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\3.1.12\Microsoft.Win32.SystemEvents.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'WindowsFormsApp1.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.12\System.Buffers.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'WindowsFormsApp1.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.12\System.Collections.NonGeneric.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.

VS 2019 Community 16.8.5

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @JayJaeger-5755 ,

Thank you for your feedback and thanks for sharing the detailed information(results) with me.

From the results message that you shared, I see you are using Windows Forms (.NET Core) project, if I am right, I think the project you created to test in Visual Studio 2017 was a Windows Forms (.NET Framework) project? Yes I can reproduce your issue on my side this time, because I change to test on a Windows Forms (.NET Core) project.


1 Vote 1 ·

As you know, .NET Core support for building Windows desktop applications started(released) in September(2019), so I think, two aspects for this issue, one is .NET Core has been improved and something has been changed, or maybe become more accurate for the rules which make Console.WriteLine() “fail” to appear in Output window and you need to use Debug.WriteLine() instead. The other is, probably .NET Core for WinForm projects needs to continue to be improved in Visual Studio, or this issue is a potential issue which may be accidentally ignored. I suggest you report this issue to Developer Community from VS > Help > Send Feedback > Report a problem...

Best Regards,
Tianyu


0 Votes 0 ·
TianyuSun-MSFT avatar image
0 Votes"
TianyuSun-MSFT answered TianyuSun-MSFT edited

Hi @JayJaeger-5755 ,

Welcome to Microsoft Q&A forum.

Typically, Console.WriteLine() writes to Console, since the Output Window is not console, we can use System.Diagnostics class library(the Debug class or the Trace class) to send messages to the Output window.

But under certain circumstances, Console.WriteLine( ) also works and the message will appear in the Output window. I tested on my side and I noticed that the Console.WriteLine( ) did show the message in my Output window. If you did the same thing like I tested but this issue remains, I suggest you start Visual Studio 2019 in Safe Mode(run devenv /SafeMode in Developer Command Prompt for VS 2019) and set the breakpoints for the “comment” and start debugging, press Step Into(F11) to see if VS hit the breakpoint and will the message in Output windows appear?

70415-debug.png

Best Regards,
Tianyu


If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



debug.png (36.6 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Maybecompletelyw0-8158 avatar image
1 Vote"
Maybecompletelyw0-8158 answered JayJaeger-5755 commented

Have you by any chance redirected output to 'Immediate Window' in 'Debug->Options...'?

70309-output.jpg



output.jpg (114.0 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Yes it was checked. I have only been using 2019 for a week or so, and had not changed much, and it is certainly possible that I checked that box in an attempt to make the Console.WriteLine output visible.

So, yeah, that helps, in that now Debug.WriteLine goes to the Output window (which is useful, because the Output window persists even after one stops debugging the application.)

But the question still remains: where is Console.WriteLine output going, and why isn't it showing up in the Output window, as it did in VS 2017? Was this an intentional change? Was it documented anywhere? Certainly seems to violate the "principle of least surprise".

0 Votes 0 ·