Visual Studio 2008 debug.print not displaying output to immediate window

lcha
lcha used Ask the Experts™
on
Hello,

I am trying to debug visual basic .net code using Visual Studio 2008.   The project is set up in configuration mode as "debug".  

I have a try and catch statement in the code.  When I run the code (f8), it errors out midway and goes to the Catch statement but it skips over the debug.print statement and nothing diplays in immediate window.   I can put a debug.print anywhere in the code and it's just gets skipped over.

Please advise any insight for what the problem could be.   Thanks!


Catch ex As Exception
            Debug.Print(ex.Message)

        Finally
            objWriter.WriteLine("Finishing Process at " & TimeOfDay)
            objWriter.Flush()
            objWriter.Close()
            objWriter = Nothing

        End Try
    End Sub

The immediate window is showing:
Step into: Stepping over non-user code 'System.ComponentModel.Design.RuntimeLicenseContext.GetLocalPath'
Step into: Stepping over non-user code 'System.ComponentModel.Design.RuntimeLicenseContext.GetSavedLicenseKey'
Step into: Stepping over non-user code 'System.ComponentModel.LicenseManager.LicenseInteropHelper.GetCurrentContextInfo'
Step into: Stepping over non-user code 'System.ComponentModel.LicenseManager.LicenseInteropHelper.GetCurrentContextInfo'
Step into: Stepping over non-user code 'System.ComponentModel.LicenseManager.LicenseInteropHelper.GetCurrentContextInfo'
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in Microsoft.VisualBasic.dll
Step into: Stepping over non-user code 'Microsoft.VisualBasic.CompilerServices.ProjectData.ClearProjectError'
Step into: Stepping over non-user code 'Microsoft.VisualBasic.DateAndTime.TimeOfDay.get'
Step into: Stepping over non-user code 'System.IO.StreamWriter.Flush'
Step into: Stepping over non-user code 'System.IO.StreamWriter.Close'
Step into: Stepping over non-user code 'Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly'
Step into: Stepping over non-user code 'System.Threading.ExecutionContext.Run'

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
Are you building a Release version instead of a Debug version?

What is F8?

Author

Commented:
I believe it release version ... unless I don't properly understand how to verify it.   See the screenshot for the configuration mgr.
F8 is the button I click to begin stepping thru the code line by line.
configmgr.png

Commented:
See where it says "Active solution configuration"?  That says "Debug", which is what you want.

Which language are you using?  Which version of Visual Studio (year?, Express?)?
Become a CompTIA Certified Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Author

Commented:
visual studio 2008 Professional Edition

Commented:
From the Tools menu, choose Options.
Click on Debugging in the left panel. Click General.
Scroll down. Is "Redirect all Output Window text to the Intermediate Window" checked?

Commented:
Or choose "Output" from the View menu and look at the end of the Output tab.

Author

Commented:
Is "Redirect all Output Window text to the Intermediate Window" checked?
- this is checked

The "View" menu doesn't have an option for "Output"
- I see output if I go to Debug --> Windows ---> Output... if I click here though the window is empty.

Commented:
I'm using C#.  Apparently the menu layout is different.  Also, single-step is different (F10 instead of F8).

When "Redirect..." is not checked for me, Debug.Print writes to the Output window; when checked, Intermediate.  You might try unchecking it to see whether anything appears in Output.

Can you set a breakpoint on the Debug.Print statement?

Author

Commented:
I set the breakpoint but once the code starts running, it skips past the breakpoint and stops on the line after where I had set the breakpoint.

The red dot that marks the breakpoint also gets shifted down one.
Commented:
That suggests that VS does not think your Debug.Print is an executable statement (ie, it is not being compiled).

From your Project menu, choose xxx Properties (where xxx is your program name); it's at the bottom.  Click on the Build tab.  If "Define DEBUG constant" is not checked, check it.

When you build your program for release, "Define DEBUG constant" should not be checked.

Author

Commented:
Ok, I found it after looking around a while.  

followed your instructions Project Menu --> xxx Properties

I went to the "Compile" tab and then Advanced Compile options and found the check box you mentioned.  

After checking it, the debug.print works!   thank you!




Commented:
You're welcome.  Curiously, that flag does not seem to matter in C#.  It was off in my project.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial