1

In Visual Studio 2017 we saw the removal of Visual Studio Hosting Process. This supposedly came with the downside of Console.WriteLine no longer working for application that ran without an attached console (for example in WPF).

At least this has been my understanding. But this to my surprise doesn't seem completely true.

Creating a .NET Framework 4.8 WPF project in Visual Studio 2019 it seems to be able to use Console.WriteLine just fine (unexpectedly) and the results show up in the visual studio output window.

Meanwhile an identical project running .NET Core does not seem to print anything to the output console (as i would expect might i addd). In both cases the project is being ran with the output type set as Windows Application, so no console is being attached to my knowledge.

This is a rather peculiar issue, as i expected Console.WriteLine to not work in both cases. But it seems like there is no information to be found about why this works for a .NET Framework Wpf application, and more so why it would work under Framework but not under Core.

I myself normally use Debug.WriteLine and Trace.WriteLine, but would like to know why Console.WriteLine still (even in Visual Studio 2019) works even though it shouldn't.

Black Lotus
  • 2,377
  • 3
  • 14
  • 18

2 Answers2

0

You can use Debug.WriteLine() which under System.Diagnostics to add some words in Output window.There is some explanation in Console.WriteLine does not output to Output Window in VS 2017.

DasiyTian_1203
  • 1,038
  • 1
  • 6
  • 16
  • I am aware and use Debug and Trace myself, the quesion (presumebly asked questianoble) was Why even with the removal of Visual Studio Hosting Process Console.WriteLine still works in Visual Studio 2019 for a .NET Framework WPF application ran as a Windows Application. – Black Lotus Aug 04 '20 at 11:06
0

The net core framework has quite a number of changes compared to .Net old. The porting of code wasn't just cut and paste and you can find subtle differences in behaviour when you stray off the path most used.

The standard out for console.writeline is logically the console window. Seeing as how there is no console window for a wpf app it's arguably the behaviour you're seeing with .net old which is "wrong".

If you particularly wanted to use console.writeline rather than debug.writeline then you could give it a console window to output to.

Change your project "Output Type" to console in Project settings. Right click your project

Properties > Application tab >

Change the drop down under "Output type" to console. When you hit f5 you then get a console window as well as mainwindow.

Andy
  • 11,864
  • 2
  • 17
  • 20
  • Could you explain what you mean with .net old? Just weird behaviour with framework? I personally always use debug and trace, didn't expect console to even work, but it seems like it does (which as far as i'm aware shouldn't be possible) i'm rather curious to know as to why it works with .net framework in a wpf project. – Black Lotus Aug 04 '20 at 11:14
  • 1
    .Net that isn't net core. Console.writeline didn't work in wpf at one time. I guess someone raised a bug report and someone at ms decided a work round was appropriate. Find those people and you'd have a definite answer. – Andy Aug 04 '20 at 11:34