I\'m trying to debug a C# application. The method:
System.Diagnostics.Debug.WriteLine(\"something\");
should do the work, but in the Output
I just ran into this issue with Visual Studio 2010 and 2017 and this is what I did to get it to work and I have no explanation as to why it now works.
What I did to get it work. I created a new Windows Form project and added a button which when pressed executed Console.WriteLine("Test"). I saw "Test" in the Output Window. I then loaded my real project and added a button to execute Console.WriteLine("Test") and now it produced output. Further Console.WriteLine statements worked from then on.
There's an option under Tools-Options-Debugging-General, Redirect all Output Window text to the Immediate Window. Make sure that's disabled. However, by default it isn't, so I doubt that's your issue. You can also just check your Immediate Window to see if it's outputting there.
You might also want to try resetting all your environment settings. (Tools - Import and Export Settings - Reset all settings.)
If all else fails, try the old restart of Visual Studio. Worked for me.
Have you checked to make sure you're compiling in Debug mode? If you compile in Retail / Release mode you will see this behavior.
You should be able to see this information on Visual Studio's toolbar. There will be a combo box which will say Release or Debug. If it says Release, switch it to Debug.
In certain profile settings, this combo box will not be visible by default. You'll have to access it through the project properties page. It will be on the build / compile tab.
IF you use shortcuts, make sure you press F5
to Start Debugging mode (not Ctr+F5).
F5 Starting Debugging
CTRL+F5 Starting Without Debugging
You need to explicitly add the system's Console
as a TraceListener in order for the output to appear in the console. According to Microsoft's documentation, this code should do the trick. This is C# code, but the link I provided contains examples for the other .NET languages.
using System;
using System.Data;
using System.Diagnostics;
class Test
{
static void Main()
{
Debug.Listeners.Add(new TextWriterTraceListener(Console.Out));
Debug.AutoFlush = true;
Debug.Indent();
Debug.WriteLine("Entering Main");
Console.WriteLine("Hello World.");
Debug.WriteLine("Exiting Main");
Debug.Unindent();
}
}