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

37
DEV339 Best Practices for Debugging Visual Studio .NET Applications Keith Pleas Architect, Guided Design [email protected] m

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

Page 1: DEV339 Best Practices for Debugging Visual Studio.NET Applications Keith Pleas Architect, Guided Design keithp@guideddesign.com.

DEV339Best Practices for Debugging Visual Studio .NET Applications

Keith PleasArchitect, Guided [email protected]

Page 2: DEV339 Best Practices for Debugging Visual Studio.NET Applications Keith Pleas Architect, Guided Design keithp@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

Page 3: DEV339 Best Practices for Debugging Visual Studio.NET Applications Keith Pleas Architect, Guided Design keithp@guideddesign.com.

3

Types of “Bugs”

Inconsistent User Interfaces

Un-met expectations

Poor performance

Crashes

Data corruption

Page 4: DEV339 Best Practices for Debugging Visual Studio.NET Applications Keith Pleas Architect, Guided Design keithp@guideddesign.com.

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

Page 5: DEV339 Best Practices for Debugging Visual Studio.NET Applications Keith Pleas Architect, Guided Design keithp@guideddesign.com.

5

Debugging Process

Tracking & catagorization

Version control

Change control

Daily builds

Unit tests

Smoke tests

Page 6: DEV339 Best Practices for Debugging Visual Studio.NET Applications Keith Pleas Architect, Guided Design keithp@guideddesign.com.

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

Page 7: DEV339 Best Practices for Debugging Visual Studio.NET Applications Keith Pleas Architect, Guided Design keithp@guideddesign.com.

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

Page 8: DEV339 Best Practices for Debugging Visual Studio.NET Applications Keith Pleas Architect, Guided Design keithp@guideddesign.com.

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

Page 9: DEV339 Best Practices for Debugging Visual Studio.NET Applications Keith Pleas Architect, Guided Design keithp@guideddesign.com.

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

Page 10: DEV339 Best Practices for Debugging Visual Studio.NET Applications Keith Pleas Architect, Guided Design keithp@guideddesign.com.

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

Page 11: DEV339 Best Practices for Debugging Visual Studio.NET Applications Keith Pleas Architect, Guided Design keithp@guideddesign.com.

11

Customizing <F5>

demodemo

Page 12: DEV339 Best Practices for Debugging Visual Studio.NET Applications Keith Pleas Architect, Guided Design keithp@guideddesign.com.

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

Page 13: DEV339 Best Practices for Debugging Visual Studio.NET Applications Keith Pleas Architect, Guided Design keithp@guideddesign.com.

13

Debugging .NET DLLs

Cannot debug DLLs directly

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

2. Manually attach

Page 14: DEV339 Best Practices for Debugging Visual Studio.NET Applications Keith Pleas Architect, Guided Design keithp@guideddesign.com.

14

Debugging a DLL

demodemo

Page 15: DEV339 Best Practices for Debugging Visual Studio.NET Applications Keith Pleas Architect, Guided Design keithp@guideddesign.com.

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

Page 16: DEV339 Best Practices for Debugging Visual Studio.NET Applications Keith Pleas Architect, Guided Design keithp@guideddesign.com.

16

Debugging XML Web Services

demodemo

Page 17: DEV339 Best Practices for Debugging Visual Studio.NET Applications Keith Pleas Architect, Guided Design keithp@guideddesign.com.

17

SQL Server Debugging

Two ways1. Use Server Explorer

Debug stored procedures and functions

2. Call procedure from applicationSet breakpoint

Enable SQL debugging

Page 18: DEV339 Best Practices for Debugging Visual Studio.NET Applications Keith Pleas Architect, Guided Design keithp@guideddesign.com.

18

Debugging SQL Stored Procedures

demodemo

Page 19: DEV339 Best Practices for Debugging Visual Studio.NET Applications Keith Pleas Architect, Guided Design keithp@guideddesign.com.

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?
Page 20: DEV339 Best Practices for Debugging Visual Studio.NET Applications Keith Pleas Architect, Guided Design keithp@guideddesign.com.

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?

Page 21: DEV339 Best Practices for Debugging Visual Studio.NET Applications Keith Pleas Architect, Guided Design keithp@guideddesign.com.

21

Testing ASP.NET Web Forms

demodemo

Page 22: DEV339 Best Practices for Debugging Visual Studio.NET Applications Keith Pleas Architect, Guided Design keithp@guideddesign.com.

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

Page 23: DEV339 Best Practices for Debugging Visual Studio.NET Applications Keith Pleas Architect, Guided Design keithp@guideddesign.com.

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”/>

Page 24: DEV339 Best Practices for Debugging Visual Studio.NET Applications Keith Pleas Architect, Guided Design keithp@guideddesign.com.

24

Client Instrumentation (1)

System.Diagnostics Instrumentation support

Debug class

Trace class

Use Debug during development

Use Trace in deployed apps

Page 25: DEV339 Best Practices for Debugging Visual Studio.NET Applications Keith Pleas Architect, Guided Design keithp@guideddesign.com.

25

Client Instrumentation (2)

Conditionally compiled methods

Define these constants via:Project settings

Command line

In code

Page 26: DEV339 Best Practices for Debugging Visual Studio.NET Applications Keith Pleas Architect, Guided Design keithp@guideddesign.com.

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”)

Page 27: DEV339 Best Practices for Debugging Visual Studio.NET Applications Keith Pleas Architect, Guided Design keithp@guideddesign.com.

27

Client Instrumentation (4)

Trace Listeners Receive trace messages

Three predefined listenersDefaultTraceListener

EventLogTraceListener

TextWriterTraceListener

Page 28: DEV339 Best Practices for Debugging Visual Studio.NET Applications Keith Pleas Architect, Guided Design keithp@guideddesign.com.

28

Tracing in Windows Applications

demodemo

Page 29: DEV339 Best Practices for Debugging Visual Studio.NET Applications Keith Pleas Architect, Guided Design keithp@guideddesign.com.

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”%>

Page 30: DEV339 Best Practices for Debugging Visual Studio.NET Applications Keith Pleas Architect, Guided Design keithp@guideddesign.com.

30

Tracing in ASP.NET

demodemo

Page 31: DEV339 Best Practices for Debugging Visual Studio.NET Applications Keith Pleas Architect, Guided Design keithp@guideddesign.com.

31

Additional Debuggers

GUI Debugger

Console Debugger

Deployment considerations

Page 32: DEV339 Best Practices for Debugging Visual Studio.NET Applications Keith Pleas Architect, Guided Design keithp@guideddesign.com.

32

Summary

Debugging client applications

Debugging Web applications

Debugging SQL Server

Tracing

Page 33: DEV339 Best Practices for Debugging Visual Studio.NET Applications Keith Pleas Architect, Guided Design keithp@guideddesign.com.

33

Ask The ExpertsGet Your Questions Answered

13:00 to 15:00 Thursday 3 July

Page 34: DEV339 Best Practices for Debugging Visual Studio.NET Applications Keith Pleas Architect, Guided Design keithp@guideddesign.com.

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

Page 35: DEV339 Best Practices for Debugging Visual Studio.NET Applications Keith Pleas Architect, Guided Design keithp@guideddesign.com.

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

Page 36: DEV339 Best Practices for Debugging Visual Studio.NET Applications Keith Pleas Architect, Guided Design keithp@guideddesign.com.

36

evaluationsevaluations

Page 37: DEV339 Best Practices for Debugging Visual Studio.NET Applications Keith Pleas Architect, Guided Design keithp@guideddesign.com.

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.