Skip to content

Instantly share code, notes, and snippets.

@unitycoder
Created December 6, 2022 10:37
Show Gist options
  • Select an option

  • Save unitycoder/35be6358ff9bbf6a5d42d624486ef516 to your computer and use it in GitHub Desktop.

Select an option

Save unitycoder/35be6358ff9bbf6a5d42d624486ef516 to your computer and use it in GitHub Desktop.
wpd .net 6.0 application doesnt show console.writeline, but in wpd .net 4.8 application it works (VS2022)

QUESTION: .net 6.0 application doesnt show console.writeline, but .net 4.8 does work

ANSWER chatGPT

The Console.WriteLine method is used to write a line of text to the console window in a .NET application. In .NET 6.0, the Console.WriteLine method will only write to the console window if the application is a console application, not if it is a Windows Forms or WPF application. This is because console applications have a console window where the output from Console.WriteLine is shown, but Windows Forms and WPF applications do not have a console window.

If you are using .NET 6.0 and your application is a Windows Forms or WPF application, the Console.WriteLine method will not write anything to the console window, and you will not see any output from Console.WriteLine in the Output panel in Visual Studio.

To see the output from Console.WriteLine in a Windows Forms or WPF application in .NET 6.0, you can do one of the following:

  • Use the Debug.WriteLine method instead of Console.WriteLine. The output from Debug.WriteLine will be shown in the Output panel when running the application in Debug mode.
  • Redirect the output from Console.WriteLine to a different output stream, such as a file or a log, by using the Console.SetOut method and providing a custom TextWriter that writes to the desired output.
  • If you are using a WPF application, you can add a text box to the window and use the Console.SetOut method to redirect the output from Console.WriteLine to the text box, as shown in the previous answer.

Note that the Console.WriteLine method will work as expected in .NET 4.8, because in .NET 4.8 the Console.WriteLine method will write to the console window regardless of whether the application is a console application, a Windows Forms application, or a WPF application. However, in .NET 6.0 and later versions, the behavior of the Console.WriteLine method has been changed to only write to the console window for console applications.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment