In the C#12 In a Nutshell book, it says:
When running WPF or Windows Forms applications under
Visual Studio, the Console’s output is automatically redirected
to Visual Studio’s output window (in debug mode)
However, I tried this in the code behind:
using System.Diagnostics;
using System.Windows;
namespace WPFHelloWorld
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
Debug.WriteLine("Hello rr Debug");
Console.WriteLine("Hello rr");
}
}
}
And I only see the output of Debug.WriteLine (so the code is reached).
I checked the Output tab and the Immediate Window tab.
I don’t see the “Hello rr” in either of them.
I see “Hello rr Debug” in the Output tab.
Why is this not working like the book says it should?
Is this a bug of Visual Studio? I know the good practice is to use Debug.WriteLine("Hello rr Debug"); in WPF apps since there is no Console. My question is why is the Console’s output not redirected when it says it should.
Things I already did:
- I made sure I was running in Debug Mode.
- I restarted my computer.
- I reinstalled Visual Studio.
- I resinstalled my .NET sdk
- I tried dotnet 8.0.401 and 9.0.101
- I checked Windows Update.