Debugging Managed Code Tips

Set Breakpoints on Optimized Code

CLR has an issue: when JIT compiling optimized code, the mapping between x86 and IL is not kept. Thus when you attach the debugger to a process running optimized code, you may often not be able to set break points. To work around this issue, you can launch the application under the debugger rather than attach to it. When optimized code is JIT compiled when a debugger is present, the x86 to IL map is preserved. You can also create .ini file per assembly that tells the JIT compiler to generate the map. See this MSDN topic: Making an Image Easier to Debug.

Also, if your code is a C++/CLI mixed mode assembly, you may want to disable the option called Enable Just My Code under the tools/Options/Debug.

Debug Into Native Code

To debug into native code when calling a (PInvoke) native function, you need to go to Project->Properties, and make sure Enable Unmanaged Debugging is checked.

Execute permission denied on object 'sp_sdidebug'

If you are debugging a W3Wp process of a Web Service that executes some SQL stored procedures in SQL server 2000, you may get a SQL exception "Execute permission denied on object 'sp_sdidebug' , database 'master', owner 'dbo'". To solve it, you can simply just select "Managed Code" only and not select "T-SQL" when you try to attach the process.

Debug IIS Related Issues

To debug IIS related issues, you should download Internet Information Services (IIS) 6.0 Resource Kit Tools. The IIS 6.0 Resource Kit Tools can help you administer, secure, and manage IIS. Use them to query log files, deploy SSL certificates, employ custom site authentication, verify permissions, troubleshoot problems, migrate your server, run stress tests, and more. For example, if you can't upload large files, you can use Metabase Explorer to change the value of (local)\LM\W3SVC\AspMaxRequestEntityAllowed and AspScriptTimeout.

Include Line Number in StackTrace

How to make the StackTrace include line number? compile your code in debug mode and deploy the .pdb file along with the assembly.

Debug Into .NET Framework Library

The source code of the .NET Framework libraries, and debugging support of them with Visual Studio 2008 is now available. Specifically, you can now browse and debug the source code for the following .NET Framework libraries:

  • .NET Base Class Libraries (including System, System.CodeDom, System.Collections, System.ComponentModel, System.Diagnostics, System.Drawing, System.Globalization, System.IO, System.Net, System.Reflection, System.Runtime, System.Security, System.Text, System.Threading, etc).
  • ASP.NET (System.Web, System.Web.Extensions)
  • Windows Forms (System.Windows.Forms)
  • Windows Presentation Foundation (System.Windows)
  • ADO.NET and XML (System.Data and System.Xml)

    You can check out Shawn Burke's "Configuring Visual Studio to Debug .NET Framework Source Code" for detailed steps. LINQ, WCF and Workflow will become available soon.

    Others

    For more debugging issues, you can check out this blog site.

    See also

  • SQL: Use Dynamic SQL Query Correctly
  • SQL 2005: Use DMV and CROSS APPLY to Get Cached Plans
  • SQL 2005: Discontinued or Deprecated Features in SQL Server 2005
  • SQL 2005: Default Trace Enabled Option
  • SQL 2005: Column Level Permissions
  • SQL 2005: SQLCMD Supports Parameterized Variables and Macro Features
  • SQL 2005: DTS Has Become SSIS now
  • SQL 2005: Microsoft SQL Server 2005 JDBC Driver
  • SQL 2005: Query Notifications in ADO.Net 2.0
  • SQL 2005: Overcome SQL Index Size Limit
  • SQL 2005: DDL Triggers
  • SQL 2005: Why Should Use 64 Bit Now
  • SQL 2005: How to Rebuild The Master Database
  • SQL 2005: A Little Trick to Install SQL 2005 Onto Your Dirty DEV Machine
  • SQL 2005: New Resource Database
  • SQL 2005: Alter Index Rebuild
  • SQL 2005: XQuery Sample
  • SQL 2005: How to Move Database
  • SQL: Use COALESCE to Generate a List
  • SQL: How to Debug SQL Deadlocks
  • .Net: How to Bypass Strong Name Check
  • Agile: Lean Software Development - An Agile Toolkit
  • ORM: How to Use nHibernate 1.2 to Call Stored Procedure to Return a Dataset Without a Mapping Entity
  • AJAX: ASP.NET AJAX Tips
  • .Net: Debugging Commands
  • .Net: How to Run NUnit And Debug Your Test Fixtures Directly from VS 2005
  • .Net: How to Add Domain User to Local Group
  • .Net: Lock Value Type?
  • .Net: How to Create an Instance of a Generic Type with Parameters
  • .Net: How to Get Address of a Managed Type
  • ORM: New Features of nHibernate 1.2
  • .Net: How to Get System Error Message from HRESULT in Managed Code
  • .Net: Use Windows PowerShell Now
  • WMI: Use WMI to Run Commands on Remote Machine
  • API: GetLogicalProcessorInformation to Detect CPUs
  • .Net: How to Implement Singleton Correctly
  • .Net: There is no MTS object context (Exception from HRESULT: 0x8004E004)
  • .Net: The Net Objectives Pattern Repository
  • Web: Access Denied When ASP.Net Accesses Eventlog
  • Nant: Error Loading GUID of Project
  • AJAX: Ajax in Action
  • DTC: DtcGetTransactionManager Fails
  • .Net: Run .Net 1.1 COM+ Serviced Components Under .Net 2.0 Framework
  • .Net: Debugging Managed Code Tip
  • .Net: Assembly Binding Log Viewer (Fuslogvw.exe)
  • .Net: .Net Framework Design Guidelines
  • .Net: Use Global Catalog and CheckTokenMembership to Check AD Group Membership



  • THIS POST IS PROVIDED "AS-IS" WITH NO WARRANTIES AND CONFERS NO RIGHTS. Build time: Sun 03/30/2008 . ©2007 Dalun Software. All rights reserved. Back to Article List