0

I've read through other similar questions but nothing has worked for me. I've changed debugging settings to check this against the most common answers.

Project Type is a class library.

Why does this code not print anything in the output window?

public class API 
    {
        public void  BrowseDirectory() {
            string[] allFiles = Directory.GetFiles(@"C:\", "*", SearchOption.AllDirectories);

            System.Diagnostics.Debug.WriteLine(allFiles);

        }

    }
bramb84
  • 355
  • 4
  • 14
  • 1
    Do you see anything in the Immediate Window? Check that you don't have the "Redirect all Output Window text to the Immediate Window" option checked in VS options. – Kenneth K. Apr 19 '16 at 14:09
  • 1
    Possible duplicate of [Where does System.Diagnostics.Debug.Write output appear?](http://stackoverflow.com/questions/1159755/where-does-system-diagnostics-debug-write-output-appear) – Alfie Goodacre Apr 19 '16 at 14:10
  • Do you have this option disabled? `Go to Tools – Options – Debugging – General page. Under this page, you’ll find the option Redirect all Output Window text to the Immediate Window.` Try switching it. – ikkentim Apr 19 '16 at 14:11
  • I don't see anything in the Immediate Window, and I have that option unchecked. Also DEBUG and TRACE flags are both set in project properties. – bramb84 Apr 19 '16 at 14:22
  • At the top of the "Output" window there's a drop-list entitled "Show output from:". Does it say "Debug"? If not, see if you can select it from the drop-list. Also, is the DLL build by a different project? If so, are you sure you've rebuilt it (and not just the project you are debugging from)? – Matthew Watson Apr 19 '16 at 14:24
  • Output is set to Debug. DLL isn't built by another project. This is all there is. – bramb84 Apr 19 '16 at 14:25
  • Already read through the other question Alfie linked, and I have all settings set to the recommendations in that thread. Still no luck. – bramb84 Apr 19 '16 at 14:30
  • What are you expecting to see? It will only print `System.String[]`. What happens if you use `System.Diagnostics.Debug.WriteLine(string.Join("\n", allFiles));`? – Matthew Watson Apr 19 '16 at 14:30
  • expecting to see print out of each file in the directory. Still don't see anything with your line. – bramb84 Apr 19 '16 at 14:37
  • It doesn't print anything because the statement does not execute. Remove try/catch from your code so you can see the Directory.GetFiles() method fail with an UnauthorizedAccessException. Don't put them back until you know how to actually handle the exception. – Hans Passant Apr 19 '16 at 14:52
  • there is no 'try/catch' in the code. – bramb84 Apr 19 '16 at 15:01
  • Something beyond what we can see is wrong. Can you debug into the line of code in question? Can you set a breakpoint on it? – Matthew Watson Apr 19 '16 at 15:20
  • Thanks for trying to help out. I set a breakpoint but am not seeing anything during debugging. I'm pretty new to C# and .NET. I'm going to have to do some more digging. – bramb84 Apr 19 '16 at 19:16

0 Answers0