36

I have the following line in my code:

System.Diagnostics.Debug.WriteLine("Title:" + title + "title[top]: " + title[top] + "title[sub]: " + title[sub]);

When I debug I see it going to this line, but when I look at the output window in Visual Studio 2010 I don't see anything even though it shows for "Debug" and I ran using "debug > run". Why?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • Is execution going *past* that line or *to* that line? `top` or `sub` might well be causing an `IndexOutOfRangeException` if they are outside the bounds of the array. – Adam Oct 21 '12 at 17:54
  • I have to ask: Is this line written during startup? Because it sometimes is being written behind a line written by the .NET library itself and falls off-screen. Maybe try to copy paste that code fro the console in notepad and search for the expected line to determine it's really not there. – Silvermind Oct 21 '12 at 18:00
  • execution goes past that line without any problem. I thought this was all working before but can't see anything now. –  Oct 21 '12 at 18:01
  • It's not during startup. It's an ASP MVC application running locally and it should be writing whenever I select a new menu on the web browser screen. –  Oct 21 '12 at 18:04

7 Answers7

21

Check following items -

  1. DEBUG mode is selected while debugging
  2. Debug option is selected in Output window - enter image description here
  3. See if breakpoint is hitting Debug.WriteLine in code
  4. Insert Debug.AutoFlush = true at the beginning of code
  5. Try checking if Platform for the solution is set to Any CPU and not x86 (or x64).
  6. Goto Project Properties--> Web - In the Debugger section, check the the ASP.NET option

Reference for Point #5 (Read the comment, It worked for that guy)

Community
  • 1
  • 1
Parag Meshram
  • 8,281
  • 10
  • 52
  • 88
  • It shows as "Show output from Debug". I will try the flush option. –  Oct 21 '12 at 18:05
  • 3
    Point 4 seems to fix it. Thanks a lot. –  Oct 21 '12 at 18:16
  • 1
    @ParagMeshram - Thanks! It was #4 that tipped me off. In my case, I had a Trace listener defined in web.config with autoflush set to false, like so: ... Once I commented this out, it suddenly worked again. – Tsar Bomba Nov 24 '16 at 01:38
  • There is no debug option in my output window. Just "Build" and "Build Order." – Kyle Delaney Jan 23 '17 at 01:25
  • For point #1, do you mean the Solution Configurations drop-down that has "Debug" and "Release"? – Kyle Delaney Jan 23 '17 at 01:27
  • @KyleDelaney yes, that's correct. It's Solution Configurations drop-down – Parag Meshram Jan 23 '17 at 08:15
  • For point #1 it is important to note that you may have selected your debug configuration but you still need to make sure that it defines the DEBUG constant in the project properties/build menu. – Chris Jan 29 '19 at 16:00
20

For me, this solved the problem:

System.Diagnostics.Trace.WriteLine("whatever");

(using Trace instead of Debug)

Al Lelopath
  • 6,448
  • 13
  • 82
  • 139
8

In your app.config file, make sure you don't have a <clear/> element in your trace listeners.

You will effectively be clearing the list of trace listeners, including the default trace listener used for Debug statements.

Here's what this would look like in your app.config file:

<system.diagnostics>
    <trace>
      <listeners>
          <!-- This next line is the troublemaker. If it is there delete it-->
          <clear/>
      </listeners>
    </trace>
  </system.diagnostics>
Rohit Vats
  • 79,502
  • 12
  • 161
  • 185
6

For me, I needed to do this to solve the problem:

1. Open the project's property page
2. Under Build tab, check "Define DEBUG constant" and "Define Trace constant"

Voila!

JustAPup
  • 1,720
  • 12
  • 19
2

I had the same problem. Using Trace.WriteLine and checking "Define DEBUG constant" did not work for me.

I noticed that the output messages were found in Immediate window, instead of Output window.

Then I unchecked "Redirect all Output Window text to the Immediate Window" option in tools and solved my problem.

0

Using "System.Diagnostics.Debug.WriteLine" I've output in the Immediate Window :-O

Lucio Flavio
  • 91
  • 2
  • 3
0

Also, check that the "Program Output" is checked in the Messages selection (right-click in Output window.

AdvApp
  • 1,094
  • 1
  • 14
  • 27