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?

4
  • Flush might solve the problem. You can also set AutoFlush to true before writing debug stuff.
    – dialer
    Oct 6, 2012 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 6, 2012 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 6, 2012 at 18:52
  • 7
    Are you in a debug build? Is the "DEBUG" symbol defined for the project? Oct 6, 2012 at 18:55

4 Answers 4

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.

2
  • 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 9, 2016 at 9: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 9, 2016 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
  • Not for me, see answer above regarding the Debug Compilation Symbol
    – userSteve
    Dec 9, 2016 at 9:48
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"

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.