3

We have a solution with multiple projects after running the code from VS the output normally seen from Debug.Writeline statements just cease to appear. I mention the multiple projects because the output from one of the projects continues to appear. However, the other project consistently stops showing the output from the statements.

It's starting to drive me crazy. I should mention this is also occurring for a second developer on the project. Anyone seen this before, or have any ideas?

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
Jay
  • 5,897
  • 1
  • 25
  • 28

6 Answers6

4

Follow these steps, it works for me

  1. Right click on your project
  2. Select Properties
  3. Select tab Build
  4. Make sure Define DEBUG constant is checked

Hope that helps

onmyway133
  • 45,645
  • 31
  • 257
  • 263
  • 1
    Thanks for the response. That option was already selected in all the projects. Further, in case anyone else finds themselves here... In VS2010 that is in the compile tab, and in the case of vb.net is in the advanced compile dialog from there – Jay Oct 17 '12 at 13:50
  • This in combination with the answer from @Cor helped print the Debug.WriteLine statements to Output window. – Siva Senthil Oct 31 '18 at 06:28
4

After being tormented by this for years I finally found the cause and the solution in this Stack Overflow question: vs2010 Debug.WriteLine stops working

It seems that Visual Studio's handinlg of debug.writeline can't handle multiple processeses that each use multiple threads correctly. Eventually the 2 processes will deadlock the portion of visual studio that handles the output, causing it to stop working.

The solution is to wrap your calls to debug.writeline in a class that synchronizes across processes using a named mutex. This prevents multiple processes from writing to debug at the same time, nicely side stepping the whole deadlock problem.

The wrapper:

public class Debug
{
     #if DEBUG
         private static readonly Mutex DebugMutex =new Mutex(false,@"Global\DebugMutex");
     #endif

     [Conditional("DEBUG")]
     public static void WriteLine(string message)
     {
         DebugMutex.WaitOne();
         System.Diagnostics.Debug.WriteLine(message);
         DebugMutex.ReleaseMutex();
     }

     [Conditional("DEBUG")]
     public static void WriteLine(string message, string category)
     {
         DebugMutex.WaitOne();
         System.Diagnostics.Debug.WriteLine(message,category);
         DebugMutex.ReleaseMutex();
     }
}

Or for those using VB.NET:

Imports System.Threading

Public Class Debug
#If DEBUG Then
  Private Shared ReadOnly DebugMutex As New Mutex(False, "Global\DebugMutex")
#End If

<Conditional("DEBUG")> _
Public Shared Sub WriteLine(message As String)
    DebugMutex.WaitOne()
    System.Diagnostics.Debug.WriteLine(message)
    DebugMutex.ReleaseMutex()
End Sub

<Conditional("DEBUG")> _
Public Shared Sub WriteLine(message As String, category As String)
    DebugMutex.WaitOne()
    System.Diagnostics.Debug.WriteLine(message, category)
    DebugMutex.ReleaseMutex()
End Sub
End Class
Community
  • 1
  • 1
Bradley Uffner
  • 16,641
  • 3
  • 39
  • 76
2

I had the same problem with Visual Studio 2010. None of the above solutions worked in my case, but I solved it like this:

  1. Right-click on your project.
  2. Select Properties.
  3. Click the Compile tab.
  4. Scroll down to "Advanced Compile Options".
  5. Change the value for "Generate debug info" from "pdb-only" to "Full".

No idea what it's for exactly, but now my Debug.Print statements appear in the Immediate Window again I can finally get back to work.

Cor
  • 23
  • 4
  • Though navigation to the screen might be relevant for VS 2010 but this problem is relevant even when we use VS 2015. In VS 2015 the "Advanced" option is inside the Build tab of project properties. In combination with the answer from @onmyway133 print messages using Debug.WriteLine statements to Output window worked for me. – Siva Senthil Oct 31 '18 at 06:29
  • This solved it for me too, on Visual Studio 2019. I'd noticed that I was getting Debug output from some projects but not others. I've no idea how that option ever got unticked, we never go in there. – ChrisA May 31 '22 at 08:16
1

you should try DebugView from Microsoft SystemInternals.

http://technet.microsoft.com/en-us/sysinternals/bb896647

Regards, Allen

Haojie
  • 5,665
  • 1
  • 15
  • 14
  • Interesting. And seems useful. But it doesn't really solve the issue in this case. Let's assume I can't install anything, and would rather actually make Visual studio work as intended. – Jay May 13 '11 at 13:45
  • OK. Try to check your solution configuration manager and to see if all projects are in Debug configuration when you set your "Active solution configuration" to Debug. – Haojie May 14 '11 at 05:16
  • Hi D., any updatse from your side? It is indeed very strange. – Haojie May 19 '11 at 03:32
  • I ended up using the setting to send all the debug output to the immediate window... which oddly enough seems to be working. Not really what I want, but at least I have the output. – Jay May 24 '11 at 14:21
1

Try checking if Platform for the solution is set to Any CPU and not x86 (or x64). I used x86 to enable Edit and Continue and then lost Debug output. After going back to AnyCPU the Output is also back.

  • That could certainly be my issue, as my setting and the other programmers in question all have ours set to x86. I can't really make that change long term... but I will give it a shot to at least test it. – Jay Jun 09 '11 at 10:12
  • I got the same problem, and changing the platform does solve it. – Eugenio De Hoyos Sep 11 '12 at 16:08
0

Got this in VS 2015. All of a sudden all Debug.WriteLine "stops working" (not showing in Output window). After going crazy about this for about an hour I found the problem: 1. Right click In output window (output from Debug) 2. Check that "Program output" is checked