2

Today I've ran into a strange thing while testing my WPF app. Visual Studio was in Debug mode. I've created a routed event handler method and wanted to test if the calling was being done correctly, so I put Console.WriteLine("test"); into that method and I was expecting to see the output (the "test" word) in the Output window of the Visual Studio. There didn't appear anything, but I think it should have (tested later on by showing a MessageBox).

I thought it should have appeared, because before this, I was using Console class to display messages to the output window, and it did allways work. So it quite surprise me, because this exact thing worked for me beforehand!

I found a "sollution", switching the project setting "Output type" to "Console App", but, as I expected, a Consolle appeared on the start of the application.

Could anyone please explain me how does the Console methods work in wpf apps in the default setting, and possibly what to use for the correct behaviour in the debugging?

Krepsy 3
  • 63
  • 1
  • 2
  • 11

2 Answers2

4

I suggest you use the System.Diagnostics.Debug.WriteLine(); The output will display in the output window inside of VS directly.

Of course, you could also create a Console window manually before you actually call any Console.Write methods:

No output to console from a WPF application?

Jack Zhai
  • 6,230
  • 1
  • 12
  • 20
  • @Krepsy 3, What about this issue? Do you will use console window manually or System.Diagnostics.Debug.WriteLine()? – Jack Zhai Jun 26 '17 at 07:13
0

Console.Writeline works fine in vs2017, not working in vs2019. (tested by opening the same project in vs2017)

mgear
  • 1,333
  • 2
  • 22
  • 39