views:

776

answers:

7

In the past, perhaps versions of Visual Studio prior to the 2008 that I am using now, I would do something like this in my VB.NET code:

System.Diagnostics.Debug.WriteLine("Message")

..and the output would go to the output window.

Now it doesn't. Something must first apparently be enabled.

If this involves "attaching a debugger", please explain how to do it. It seems to me that it should just work without too much of a fuss.

Here's a video explaining the issue in real time and showing you all my settings

http://screencast.com/t/YQnPb0mJcs

I'm using VS2008

+6  A: 

It should go to the output window if your app is compiled with the Debug configuration rather than the Release configuration. But instead of Debug.WriteLine(), try using Trace.WriteLine() (optionally with a ConsoleTraceListener attached).

Joel Coehoorn
Under Project Properties, Debug tab, the Configuration dropdown is set to Debug. Still no messages on the Immediate or Output windows.
Velika
Trace while attaching a listener? How to attach a Listener (Console window? Sounds ugly an old)
Velika
You don't need the ConsoleTraceListener. It's just an option if you want to write the console, and it sounds like you don't. Just call Trace.WriteLine().
Joel Coehoorn
+2  A: 

Check your Immediate Window, you might have all the output redirected to it

Josh W.
Nope. Nothing there. See my answer to Johnny
Velika
+4  A: 

Check to see if the "Redirect all Output Window text to the Immediate Window" is checked under Tools -> Options -> Debugging -> General.

Alternatively, you can use the Console.WriteLine() function as well.

JonnyD
I did check the option you indicated but, after executing the Debug.writeline, the output still does not go to the Immediate Window. I'd rather not use the Console window.
Velika
Console isn't always available from winforms or wpf programs.
Joel Coehoorn
+2  A: 

Do you definitely have the DEBUG constant defined? Check under project properties > Compile > Advanced Compile Options (there's a checkbox for the DEBUG constant, if it isn't checked your Debug.XXX statements will not be executed).

Hamish Smith
The "Define DEBUG Constant" is checked, but the "Custom Constants" text box is empty. Should a value be in the "Custom Constants" textbox if the checkbox is checked?
Velika
No, custom constants is for custom compilation constants. The TRACE and DEBUG constants are built in
Hamish Smith
+1  A: 

Some extra ideas to try or check:

  • Put a breakpoint before Debug.WriteLine and see what's in System.Diagnostics.Trace.Listeners collection. You should see DefaultTraceListener. If you don't see anything, then no one is listening and that's problem.
  • Is it possible that the trace listeners being cleared/modified somewhere such as in config file or in the code?
  • Have you installed any package or add-in to Visual Studio? or using a third-party library?
  • Can you see debug messages outside of VS? There is a SysInternals application called DebugView that monitors and shows debug output in your system. Run that tool and then run your application. You should see your debug message in DebugView. At least you will know that your application is outputting debug messages but VS does not seem to be listening.
  • Have you gone through the contents of the output window to see if there is any exception or error being reported. Your debug output is not there but there might be somethings in there that can provide some clues.
Mehmet Aras
I executed this line: Debug.WriteLine("test")Then executed this in th eImmediate Window:? System.Diagnostics.Trace.Listeners.Count1? System.Diagnostics.Trace.Listeners(0).Name"Default"The Sys Internals tool showed:Debug View:[4812] test No output to the Immeditate or Output Window
Velika
A: 

Right-click in the output window, and ensure "Program output" is checked.

PaulS
A: 

Do visual studio running "debugging" (F5) when you trying to see the output?

In order that Visual Studio will output the message, and must listen to the DefaultTraceListener. Make sure that the debugger is running.

Mendy