DEV 339 Best Practices for Debugging Visual Studio

DEV 339 Best Practices for Debugging Visual Studio. NET Applications Keith Pleas Architect, Guided Design keithp@guideddesign. com

Overview About debugging What's new in Visual Studio. NET 2003 Debugging in Visual Studio. NET Client applications Web applications SQL Server database objects Tracing Additional Debuggers 2

Types of “Bugs” Inconsistent User Interfaces Un-met expectations Poor performance Crashes Data corruption 3

Debugging: A Methodology by John Robbins, Wintellect 4 Duplicate the bug Describe the bug Always assume that the bug is yours Divide and Conquer Think creatively Leverage tools Start heavy debugging Verify that the bug is fixed Learn and share

Debugging Process Tracking & catagorization Version control Change control Daily builds Unit tests Smoke tests 5

Visual Studio. NET Errors versus Warnings For VB, on for manual compiles by default Listed for C#, grovel for VB Attributes Debugger. Step. Through. Attrribute Opposite of what you’d think You _can_ set breakpoints Debugger. Hidden. Attribute 6

Visual Studio. NET 2003 What’s New in the Debugger Viewing C# unhandled exceptions Better collection display in the debugger (Array. List, Hash. Table) Alphabetically sorted view of members Intelli. Sense in the Immediate window Filtered Call Stack view 7

Visual Studio. NET 2003 What’s New in the Debugger Reload symbols from the Call Stack window Automatic stepping into Web Services Symbol server support Debugging managed dumps using Son of Strike (SOS. dll) NTSD extension 8

Cool Tip Debugging a Data. Set made easier! Question: How do you debug a Data. Set today? REPEAT Click, Expand, Scroll UNTIL ( Index Finger Becomes Sore ) Hard to determine what you’re looking at Hint: Use the Immediate window to make life a little easier 9

Debugging. NET EXEs Two ways to debug a. NET EXE Start (F 5) Manually attach to the EXE using the Processes dialog In addition, you can customize F 5 to: Debug an application remotely Debug an URL instead of your project Debug another program instead of your project 10

demo Customizing <F 5> 11

Cool Tip Expand your types automatically! Text file in Common 7PackagesDebugger directory mcee_cs. dat for C# mcee_mc. dat for MC++ 12 Allows immediate display of custom types in Watch, Quick. Watch, Data. Tips, etc. See actual file for documentation Must restart VS

Debugging. NET DLLs Cannot debug DLLs directly Two ways to debug a DLL 1. 2. 13 Specify host process in project properties Manually attach

demo Debugging a DLL 14

Debugging XML Web Services You can debug an XML Web Service: On its own Called from a ASP. NET Web Form Called from a client application That is already running 15

demo Debugging XML Web Services 16

SQL Server Debugging Two ways 1. Use Server Explorer Debug stored procedures and functions 2. Call procedure from application Set breakpoint Enable SQL debugging 17

demo Debugging SQL Stored Procedures 18

JIT debugging “Just In Time” (JIT) Debugging Allows you to debug crashes (exceptions) when application is not running under the debugger Default is off for Windows Forms <configuration> <system. windows. forms jit. Debugging="true" /> </configuration> Can select which debugger to attach with 19

Testing Your ASP. NET Application Using Different Browsers VS always uses IE when debugging an ASP. NET application What if you want to debug using other browsers? 20

demo Testing ASP. NET Web Forms 21

Remote Debugging ASP. NET Remote Debugging Local Machine 22 Remote machine 1. Setup debug components on remote machine 2. Add user to Debugger Users group 3. Typically user needs to be admin

“Troubleshooting: How do I debug an ASP. NET app on my machine? ” Troubleshooting F 5 Turn debugging on in web. config file <compilation debug=“true”/> Make sure ASP. NET debugging is turned on in your project properties When aspnet_wp. exe runs as SYSTEM, the user debugging it must be an administrator. Your web application must use Integrated Windows Authentication. 23

Client Instrumentation (1) System. Diagnostics Instrumentation support Debug class Trace class Use Debug during development Use Trace in deployed apps 24

Client Instrumentation (2) Conditionally compiled methods Define these constants via: Project settings Command line In code 25

Client Instrumentation (3) Use switch in code static Boolean. Switch switch = new Boolean. Switch(“Trace. Sample”, “Tracer”); … Trace. Write. Line. If(switch. Enabled, “Trace is running”) Change Application configuration file: Enables switch Sets trace level 26

Client Instrumentation (4) Trace Listeners Receive trace messages Three predefined listeners Default. Trace. Listener Event. Log. Trace. Listener Text. Writer. Trace. Listener 27

demo Tracing in Windows Applications 28

Tracing ASP. NET Use the Trace property Trace. Warn Trace. Write Two types: Page level trace <%@ Page Trace=“true”%> Application tracing Web. config change Read Trace. axd 29

demo Tracing in ASP. NET 30

Additional Debuggers GUI Debugger Console Debugger Deployment considerations 31

Summary Debugging client applications Debugging Web applications Debugging SQL Server Tracing 32

Ask The Experts Get Your Questions Answered 13: 00 to 15: 00 Thursday 3 July 33

Community Resources http: //www. microsoft. com/communities/default. mspx Most Valuable Professional (MVP) http: //www. mvp. support. microsoft. com/ Newsgroups Converse online with Microsoft Newsgroups, including Worldwide http: //www. microsoft. com/communities/newsgroups/default. mspx User Groups Meet and learn with your peers http: //www. microsoft. com/communities/usergroups/default. mspx 34

Suggested Reading And Resources The tools you need to put technology to work! TITLE Debugging Applications for Microsoft®. NET and Microsoft Windows®: 0 -7356 -1536 -5 Available Today Microsoft Press books are 20% off at the Tech. Ed Bookstore 35 Also buy any TWO Microsoft Press books and get a FREE T-Shirt

evaluations 36

37 © 2003 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS SUMMARY.
- Slides: 37