VisualStudio: no debug output

后端 未结 12 926
有刺的猬
有刺的猬 2020-12-24 03:13

I\'m trying to debug a C# application. The method:

System.Diagnostics.Debug.WriteLine(\"something\");

should do the work, but in the Output

相关标签:
12条回答
  • 2020-12-24 03:47

    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.

    0 讨论(0)
  • 2020-12-24 03:49

    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.)

    0 讨论(0)
  • 2020-12-24 03:51

    If all else fails, try the old restart of Visual Studio. Worked for me.

    0 讨论(0)
  • 2020-12-24 03:53

    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.

    0 讨论(0)
  • 2020-12-24 03:54

    IF you use shortcuts, make sure you press F5 to Start Debugging mode (not Ctr+F5).

    F5 Starting Debugging

    CTRL+F5 Starting Without Debugging

    0 讨论(0)
  • 2020-12-24 03:58

    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();
        }
    }
    
    0 讨论(0)
提交回复
热议问题