221

I just open a console application and I type

Console.WriteLine("Test");

But the output window doesn't show this. I go to the output window with Ctrl + W, O.

But nothing shows up when I run my program. Am I nuts or is this not supported in Visual Studio 2010 Express?

2
  • 4
    As Leif said it disappears before you can see it. Use Console.ReadKey()
    – Xaqron
    Commented Dec 19, 2010 at 0:25
  • See also stackoverflow.com/a/1583569/503688 for a mechanism to redirect console output to the debug output window.
    – yoyo
    Commented Dec 21, 2016 at 22:13

23 Answers 23

395

Console.WriteLine writes your output to the console window opened by your application (think black window with white text that appears when you open the Command Prompt.) Try System.Diagnostics.Debug.WriteLine instead.

5
  • 34
    The debug output appears in the Output window (Debug => Windows => Output). Mine wasn't open by default.
    – Appulus
    Commented Aug 21, 2013 at 10:21
  • 2
    If there is no output in the console window, also check the properties of the application under the Debug tab Start Options to make sure you do not have any command line arguments redirecting the output from the console. Commented Apr 13, 2016 at 16:03
  • And use a tool like technet.microsoft.com/en-us/sysinternals/debugview.aspx DebugView (dbgview) to receive the debug messages because they won't appear on the cmd console.
    – Roger Deep
    Commented Dec 17, 2016 at 9:54
  • Well, if you "start without debugging", you will not see the output....So you have to run your program by "start debugging"...Sounds silly, but I just know that....And don't forget to select "Debug" from the "Show output from" in the output window (In my case, the original tab is "Build")
    – vainquit
    Commented Jul 1, 2021 at 13:43
  • While this was not the actual problem for mine, But two steps you can check. 1: that you have not redirected the output via Options->Debugging->General->Redirect all output window text to.... 2: in my case, i did not have the DEBUG constant defined (check project options) / Result of having it in RELEASE
    – Angry 84
    Commented Aug 29, 2021 at 5:01
45

No satisfactory answers were provided.

System.Diagnostics.Debug.WriteLine() will write messages to the Output:debug window, but so much crap is constantly dumped into that window by every process under the sun, it is like finding a needle in a haystack to find your messages.

Console.WriteLine() does not write to any window in Visual Studio. I guess it will only write to the application console if your application creates a console in the first place, i.e. if it is a console application.

4
  • 1
    You could prefix your message with a string, e.g. ">>>" and use VSColorOutpu to highlight such lines.
    – Andreas
    Commented Feb 9, 2021 at 8:48
  • If you right click in the output window you can turn of all of the usual spammers (closing threads, loaded modules, etc). Commented Jan 20, 2023 at 14:36
  • In my case, the output appeared in the "Immediate" window. Commented Feb 8, 2023 at 17:56
  • Also, in vs2022 dotnet 4.8 wpf project it works (console.writeline is visible in output) but not in c# 7.0 wpf project)
    – mgear
    Commented Nov 6, 2023 at 9:09
31

Go to properties in you own project in the Solution Explorer window and choose application type and look for Output Type.

Change its value to Console Application.

This will make console screen besides your form. If you close the console screen, your form will be closed too.

3
  • Make my day! I can loop through my LINQ query and write to the console now which is quick cheap way of getting the correct data into the fray.
    – JustJohn
    Commented Aug 30, 2015 at 6:07
  • 1. It works for VS Enterprise as well. 2. This solution redirects messages not to Output/Debug window of VS, but to a separately opened console window. The latter is often even more convenient. Good! Commented May 15, 2021 at 18:17
  • OMFG, this was it, I initially had the project at .NET Core 3.1, I switched to .NET 8 and it reset the Output type to Windows Application! It was just opening and exiting without throwing any message and it won't print any Console.WriteLine either! Gawd!!!!! Commented Mar 15 at 23:51
25

Perhaps the console is clearing. Try:

Console.WriteLine("Test");
Console.ReadLine();

And it will hopefully stay there until you press enter.

0
8

Or you can debug by CTRL+F5 this will open ConsoleWindow waits after last line executed untill you press key.

1
  • 10
    Well, that's not really 'debugging', that's just launching the application without attaching the debugger. :/
    – damian
    Commented Nov 7, 2014 at 14:59
7

It's more than likely because you've used Console in the namespace. For example like this:

namespace XYZApplication.Console
{
    class Program
    {
        static void Main(string[] args)
       {
            //Some code;             
       }
    }
}

Try removing it from the namespace or use the full namespace instead i.e.

   System.Console.Writeline("abc");

The reason is a problem this is an issue is because you might have another clashing namespace. Example:

using System;
using AnotherNamespaceThatContainsAConsoleClass;
3
  • 1
    I didn't have any other Console in my app, but adding System. helped. Thanks.
    – kolenda
    Commented Aug 30, 2017 at 11:12
  • Why is using Console a problem? What is the explanation? What are the mechanisms? From the Help Center: "...always explain why the solution you're presenting is appropriate and how it works". Please respond by editing (changing) your answer, not here in comments (without "Edit:", "Update:", or similar - the answer should appear as if it was written today). Commented Jan 17, 2022 at 21:53
  • @PeterMortensen - have updated the response to include why using console is a problem. Thanks for the nudge.
    – nadsy
    Commented Dec 28, 2022 at 15:54
6

I run into a similar problem while running a unit test. Console.WriteLine() did not write anything into the Visual Studio Output Window.

Using System.Diagnostics.Debug.WriteLine() solved the problem.

5

The output window isn't the console. Try the methods in System.Diagnostics.Debug

5

In a Windows Forms application, both methods,

System.Diagnostics.Debug.WriteLine("my string")

and

System.Console.WriteLine("my string")

write to the output window.

In an ASP.NET Core application, only System.Diagnostics.Debug.WriteLine("my string") writes to the output window.

5

Try Ctrl + F5. It will hold your screen until you press any key.

1
  • 1
    How does that answer the question? Commented Jan 17, 2022 at 21:50
2

None of the answers here worked for me!! Most of these people here are stuck in Windows Desktop Application Consoleland. If you are a web developer using ASP.NET in Visual Studio and do not see any console or debug text, here is how to fix that:

  1. Paste the following two tests into your code so it runs both lines. These are tests for the output window:

    System.Console.WriteLine($"hello console!");

    System.Diagnostics.Debug.WriteLine($"hello debugger!");

  2. In Visual Studio choose VIEW > OUTPUT. You will see the results above in this output window after changing two settings below.

  3. When NOT DEBUGGING, in the OUTPUT window at the top under "Show Output From" choose: "YourProjectName - ASP.NET CORE Web Server". Run your code. You should see the "Console" text above.

  4. When DEBUGGING, in the OUTPUT window at the top under "Show Output From" choose: "Debugger". Run your code in debug mode. You should see the "Debug" text above.

2

A workaround I found:

Press Ctrl + Alt + I or navigate to the Debug tab → WindowsImmediate.

In your code write:

Trace.WriteLine("This is one of the workarounds");
2
  • Where is the "Debug tab*"? What window / menu? Commented Jan 17, 2022 at 21:43
  • to be honest, this worked for me! The output tab still remains empty, but the immediate window is being populated even with console.writeline
    – Mattia
    Commented Feb 27, 2023 at 22:45
2

Right click on the project in Solution Explorer and click "Clean".

Now run - press F5.

Make sure the code is as below:

Console.WriteLine("TEST");
Console.ReadLine();
1

If you use Ctrl-F5 (start without debugging) it will leave the console window open with a message "Press any key to continue". That's the easiest way to keep the console window from closing so you can see the console output.

1

Go to the Debug menu and select Options and uncheck "Redirect all Output Window text to Immediate Window"

0

Console.Writeline() shows up in the debug output (Debug => Windows => Output).

3
  • 7
    No, System.Diagnostics.Debug.WriteLine writes to Debug => Windows => Output, but not Console.WriteLine Commented Jan 5, 2013 at 1:40
  • 1
    The person asking the question is using a Console application, where Console.WriteLine() of course writes to the Console, which is the black coloured application window, looking like a DOS window. Console.WriteLine() only writes to the Debug Output Window, when it is not a Console application. Commented Jan 22, 2016 at 13:57
  • "Console.WriteLine() only writes to the Debug Output Window, when it is not a Console application." Why?
    – sydd
    Commented Feb 7, 2018 at 8:51
0

If you are developing a command line application, you can also use Console.ReadLine() at the end of your code to wait for the 'Enter' keypress before closing the console window so that you can read your output.

0
using System.Diagnostics;


Trace.WriteLine("This line will show on Output window"); 
Trace.Flush();

This works on Microsoft Team Explorer for Visual Studio 2013

Refer to microsoft.com

0

The Output window of Visual Studio 2017 have a menu called Show output from, in my case ASP.NET Core Web Server was the option to select in order to see the printed out, I came across this issue since I had it set to Build so I wasn't seeing the printed out lines at runtime.

0

There are 2 possible problems are:

  • Firstly, you have not used the using System which should be before writing code that uses "System class", as Console.WriteLine()
  • Secondly, you have not coded what happens after the Console displays "Test"

The possible solution will be:

using System;

namespace Test
{
    public static Main()
    {
        //Print to the console
        Console.WriteLine("Test");

        //Allow user to read output
        Console.ReadKey();
    }
}

It is also strategic to code Console.Write("Press any key to exit..."); on the line that precedes the Console.ReadKey(); to make the user aware that the program is ending, he/she must press any key to exit.

0

Change the execution mode to "Self Hosted". In this case, the execution console will appear and all the messages will be displayed.

0

Console.Writeline will appear in the 'Immediate Window' tab in your Visual Studio... Just do a Ctrl + Alt + i

-1

I just had the same problem. What I found on my VS Community 2022 is that you need to add Console.ReadLine(), that way the compiler shows it on the terminal window.

So if you wrote for example "Hello World" and all you saw was your file directory, with Console.Readline() it shows the actual "Hello World" string.

It's the way Visual Studio compilers work. usually on online compilers Console.Readline() will not be needed, might even be taken for an error!

Not the answer you're looking for? Browse other questions tagged or ask your own question.