Why doesn't Console.Writeline, Console.Write work in Visual Studio Express?

C#Visual Studio-2010

C# Problem Overview


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?

C# Solutions


Solution 1 - C#

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.

Solution 2 - C#

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.

Solution 3 - C#

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.

Solution 4 - C#

Perhaps the console is clearing. Try:

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

And it will hopefully stay there until you press enter.

Solution 5 - C#

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

Solution 6 - C#

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

Solution 7 - C#

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");

Solution 8 - C#

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

Solution 9 - C#

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.

Solution 10 - C#

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.

Solution 11 - C#

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();

Solution 12 - C#

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.

Solution 13 - C#

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.

Solution 14 - C#

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

Solution 15 - C#

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

Solution 16 - C#

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.

Solution 17 - C#

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

Solution 18 - C#

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");

Solution 19 - C#

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.

Solution 20 - C#

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.

Solution 21 - C#

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionShai UIView Question on Stackoverflow
Solution 1 - C#Adam MarasView Answer on Stackoverflow
Solution 2 - C#Paul GorbasView Answer on Stackoverflow
Solution 3 - C#ibrahimView Answer on Stackoverflow
Solution 4 - C#Leif AndersenView Answer on Stackoverflow
Solution 5 - C#Javed AkramView Answer on Stackoverflow
Solution 6 - C#lesscodeView Answer on Stackoverflow
Solution 7 - C#nadsyView Answer on Stackoverflow
Solution 8 - C#Sumen Kr MallickView Answer on Stackoverflow
Solution 9 - C#user6849960View Answer on Stackoverflow
Solution 10 - C#Peter HuberView Answer on Stackoverflow
Solution 11 - C#akashView Answer on Stackoverflow
Solution 12 - C#StokelyView Answer on Stackoverflow
Solution 13 - C#Jeffrey CountsView Answer on Stackoverflow
Solution 14 - C#user241636View Answer on Stackoverflow
Solution 15 - C#Svl2Nuk3View Answer on Stackoverflow
Solution 16 - C#Abdullah Ibn MannanView Answer on Stackoverflow
Solution 17 - C#Sinan ÇALIŞKANView Answer on Stackoverflow
Solution 18 - C#GurdeepBhatiaView Answer on Stackoverflow
Solution 19 - C#kuky54View Answer on Stackoverflow
Solution 20 - C#Lethu NsibandeView Answer on Stackoverflow
Solution 21 - C#Marcelo VegaView Answer on Stackoverflow