8

I am writing a simple C# Code, but the parts where Debug.WriteLine(".."); appear, get skipped. For instance:

WebClient wc = new WebClient();

        wc.Encoding = System.Text.Encoding.GetEncoding("ISO-8859-1");
        wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(SearchWordsDownloaded);

        Debug.WriteLine("test");
        wc.DownloadStringAsync(new Uri("SomeURL"));

Why is that happening?

QKL
  • 259
  • 1
  • 3
  • 11
  • `Flush` *might* solve the problem. You can also set `AutoFlush` to `true` before writing debug stuff. – dialer Oct 06 '12 at 18:50
  • Are you saying that the line is ignored while stepping through the lines of code, or that "test" is not being output to your configured destination? – Cᴏʀʏ Oct 06 '12 at 18:51
  • 1
    There is no flush here in the WP7 SDK. @Cory, it is skipped while I step through in debug mode and also when I let it run. – QKL Oct 06 '12 at 18:52
  • 7
    Are you in a debug build? Is the "DEBUG" symbol defined for the project? – Marc Gravell Oct 06 '12 at 18:55

4 Answers4

13

I was seeing this - Debug.WriteLine() statements being jumped over for a debug build with the debugger attached. Not sure why but the DEBUG compilation symbol was not being set. Go to the project properties page, build section, and within the 'Conditional compilation symbols' field enter 'DEBUG' (without quotes). That caused the debugger to start entering Debug statements again.

redcalx
  • 8,177
  • 4
  • 56
  • 105
  • This is exactly the answer that worked for me. THANKS. Anyone know the implications of adding the DEBUG compilation symbol when building a release version? – userSteve Dec 09 '16 at 09:47
  • 1
    Any Debug.Foo() call will remain in the compiled code. Without the DEBUG symbol those calls are removed (they don't make it into the compiled assembly). So although things like Debug.WriteLine() probably won't do anything (because it has nowhere to write to), Debug.Assert() for instance probably will run the assertion and throw an exception if it the assertion fails. – redcalx Dec 09 '16 at 10:35
3

The only way it can be skipped is you are running it in release.

Try cleaning the solution, and ensuring it is in debug mode and add a break point in this code segment and press F5.

1

I've had it skip Debug.Writeline statements if the Active Solution platform is set to either x86 or x64. It seems like they can only be hit if you're Configuration Manager is set to "Any CPU"

landers
  • 105
  • 9
0

This is an old post and I had the problem in Diagnostics using Debug class and Trace class in 64bit console app in Visual Studio 2017. For some who are experiencing this problem in Visual Studio 2017. What I did was to copy the configuration of a console app project properties Build->General setting.

enter image description here

Ronald Abellano
  • 774
  • 10
  • 34