DEV339 Best Practices for Debugging Visual Studio.NET Applications Keith Pleas Architect, Guided...

Preview:

Citation preview

DEV339Best Practices for Debugging Visual Studio .NET Applications

Keith PleasArchitect, Guided Designkeithp@guideddesign.com

2

Overview

About debugging

What's new in Visual Studio .NET 2003

Debugging in Visual Studio .NETClient applications

Web applications

SQL Server database objects

Tracing

Additional Debuggers

3

Types of “Bugs”

Inconsistent User Interfaces

Un-met expectations

Poor performance

Crashes

Data corruption

4

Debugging: A Methodologyby John Robbins, Wintellect

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

5

Debugging Process

Tracking & catagorization

Version control

Change control

Daily builds

Unit tests

Smoke tests

6

Visual Studio .NET

ErrorsErrors versus WarningsFor VB, on for manual compiles by defaultListed for C#, grovel for VB

AttributesDebuggerStepThroughAttrribute

Opposite of what you’d thinkYou _can_ set breakpoints

DebuggerHiddenAttribute

7

Visual Studio .NET 2003 What’s New in the Debugger

Viewing C# unhandled exceptions

Better collection display in the debugger (ArrayList, HashTable)

Alphabetically sorted view of members

IntelliSense in the Immediate window

Filtered Call Stack view

8

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

9

Cool TipDebugging a DataSet made easier!

Question: How do you debug a DataSet today?

REPEATClick, 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

10

Debugging .NET EXEs

Two ways to debug a .NET EXEStart (F5)

Manually attach to the EXE using the Processes dialog

In addition, you can customize F5 to:Debug an application remotely

Debug an URL instead of your project

Debug another program instead of your project

11

Customizing <F5>

demodemo

12

Cool TipExpand your types automatically!

Text file in Common7\Packages\Debugger directory

mcee_cs.dat for C#

mcee_mc.dat for MC++

Allows immediate display of custom types in Watch, QuickWatch, DataTips, etc.

See actual file for documentation

Must restart VS

13

Debugging .NET DLLs

Cannot debug DLLs directly

Two ways to debug a DLL1. Specify host process in project properties

2. Manually attach

14

Debugging a DLL

demodemo

15

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

16

Debugging XML Web Services

demodemo

17

SQL Server Debugging

Two ways1. Use Server Explorer

Debug stored procedures and functions

2. Call procedure from applicationSet breakpoint

Enable SQL debugging

18

Debugging SQL Stored Procedures

demodemo

19

JIT debugging

“Just In Time” (JIT) DebuggingAllows you to debug crashes (exceptions) when application is not running under the debugger

Default is off for Windows Forms

Can select which debugger to attach with

<configuration><configuration> <system.windows.forms jitDebugging="true" /><system.windows.forms jitDebugging="true" /></configuration></configuration>

Joe Nalewabau
What else do we need to mention about JIT debugging? What debug engines can I attach with etc?

20

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?

21

Testing ASP.NET Web Forms

demodemo

22

Remote Debugging ASP.NET

1. Setup debug components on remote machine

Local MachineLocal Machine

Remote machineRemote machine

Remote DebuggingRemote Debugging

2. Add user to Debugger Users group3. Typically user needs to be admin

23

“Troubleshooting: How do I debug an ASP.NET app on my machine?”

Troubleshooting F5Turn debugging on in web.config file

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.

<compilation debug=“true”/><compilation debug=“true”/>

24

Client Instrumentation (1)

System.Diagnostics Instrumentation support

Debug class

Trace class

Use Debug during development

Use Trace in deployed apps

25

Client Instrumentation (2)

Conditionally compiled methods

Define these constants via:Project settings

Command line

In code

26

Client Instrumentation (3)

Use switch in code

Change Application configuration file:Enables switchSets trace level

static BooleanSwitch switch = static BooleanSwitch switch =

new BooleanSwitch(“TraceSample”, new BooleanSwitch(“TraceSample”,

““Tracer”);Tracer”);

……

Trace.WriteLineIf(switch.Enabled, Trace.WriteLineIf(switch.Enabled,

““Trace is running”)Trace is running”)

27

Client Instrumentation (4)

Trace Listeners Receive trace messages

Three predefined listenersDefaultTraceListener

EventLogTraceListener

TextWriterTraceListener

28

Tracing in Windows Applications

demodemo

29

Tracing ASP.NET

Use the Trace propertyTrace.Warn Trace.Write

Two types:Page level trace

Application tracingWeb.config changeRead Trace.axd

<%@ Page Trace=“true”%><%@ Page Trace=“true”%>

30

Tracing in ASP.NET

demodemo

31

Additional Debuggers

GUI Debugger

Console Debugger

Deployment considerations

32

Summary

Debugging client applications

Debugging Web applications

Debugging SQL Server

Tracing

33

Ask The ExpertsGet Your Questions Answered

13:00 to 15:00 Thursday 3 July

34

Community Resources

Community Resourceshttp://www.microsoft.com/communities/default.mspx

Most Valuable Professional (MVP)http://www.mvp.support.microsoft.com/

NewsgroupsConverse online with Microsoft Newsgroups, including Worldwidehttp://www.microsoft.com/communities/newsgroups/default.mspx

User GroupsMeet and learn with your peershttp://www.microsoft.com/communities/usergroups/default.mspx

35

Suggested Reading And Resources

The tools you need to put technology to work!The tools you need to put technology to work!

TITLETITLE AvailableAvailable

TodayTodayDebugging Applications for Debugging Applications for Microsoft® .NET and Microsoft Microsoft® .NET and Microsoft Windows®: 0-7356-1536-5Windows®: 0-7356-1536-5

Microsoft Press books are 20% off at the TechEd Bookstore

Also buy any TWO Microsoft Press books and get a FREE T-Shirt

36

evaluationsevaluations

37© 2003 Microsoft Corporation. All rights reserved.© 2003 Microsoft Corporation. All rights reserved.

This presentation is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS SUMMARY.This presentation is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS SUMMARY.

Recommended