170 likes | 280 Views
Debugging and tracing in .NET. Presented by: Beeninder Dhanjal Department of Computer Science. What can be debugged?. Windows Forms Web Forms Web services Stored Procedures. Debugging elements. Project modes Breakpoints Command Window Call stack window Modules window Watch window
E N D
Debugging and tracing in .NET Presented by: Beeninder Dhanjal Department of Computer Science
What can be debugged? • Windows Forms • Web Forms • Web services • Stored Procedures
Debugging elements • Project modes • Breakpoints • Command Window • Call stack window • Modules window • Watch window • Enterprise Debugging (Remote) • Lightweight Debugger(DBGCRL.exe)
Conditional breakpoints • Click the breakpoints window icon. • Go to the breakpoints pane and right-click this breakpoint, and select Properties. • On the File tab, click the condition button. • In the breakpoint condition dialog, in the condition field, enter condition like sometextbox.Text = “29” or you can reset the Hit Counter.
Debugging window • Select the View | Other Windows | Command Window from the main menu. Example In the Command Window, enter for Example ? OrderID, and press Enter. This evaluates the value of OrderID. • Can view data adapter values. • Predefined commands
EnterpriseDebugging – Attaching to Processes • Run the application through the URL • In VS. Net select Tools, Debug Process. • In the Processes dialog box, check Show System Processes if it is unchecked • Select the aspnet_wp.exe (or w3wp.exe) process, and then click the Attach button which will open the Attach to Process window. • Set break points and debug.
Stored Procedure Debugging • Enable the SQL Debugging option by Right Clicking the Solution explorer |properties| Configuration option| Debugging. • Open Server Explorer, Browse to the database and Right click on the desired Store Procedure. • Click Edit Stored Procedure. • Place breakpoints and start Debugging.
Debugging Windows Forms • Using Debug.Writeline(); • Using Trace Example: -- Dim tfl As New TextWriterTraceListener("C:\TraceLog.txt"); -- Trace.Listeners.Add(tfl); -- Trace.WriteLine(Trace.Listeners.Count() & " trace listeners");
Assersion • Gives 3 options when the condition is met. Abort Retry Ignore Example: Trace.Assert(Interest>0) • Shows the Complete Call Stack on Debugging.
TraceSwitch Class • Open Application.config file • Between the <switches> tags enter this line of XML: <add name="mySwitch" value="2"></add> Where 1 = Only Error Messages 2 = Error and Warning Messages 3 = Informational, Warning and Error Messages. 4 = Verbose, Informational, Warning, and Error messages.
Application.Config <?xml version="1.0" encoding="utf-8" ?> <configuration> <system.diagnostics> <switches> <add name="mySwitch" value="2"></add> </switches> </system.diagnostics> </configuration>
Tracing in ASP.NET • Open the Web.Config file and replace Trace=“false” to Trace=“True” • Run the application and replace the start page in the IE with trace.axd Example http://localhost/Homework3/trace.axd • Can be done for individual files.
Tracing a Web Service • 1. In Solution Explorer, right-click the web service .asmx, click View Code • 2. uncomment Context.Trace.Write… • 3. From the main menu, select Debug | Start without debugging • 4. Start Microsoft Internet Explorer and enter http://localhost/HomeWork3/trace.axd to open the Request Details page. • 5. Click View Details.
Continued…. • 6. Scroll to Trace Information, double click WebService • 7. Close Microsoft Internet Explorer. • 8. In Solutions Explorer, double click web.config - <authorization> and change: <deny users=”?” /> to <allow users=”none” /> • 9. From the main menu, select Debug | Start without debugging