2008-01-18

Debugging SharePoint GAC dll's


Debugging sharepoint dll's is pretty straight forward and just like any other dll.

What you need:

  1. The program database file (pdb)

  2. The source files

  3. A compatible debugger (VS 2005)

  4. Access to the dll registered directory (global assembly cache/ webapp bin)


For this example we're gona debug a GAC dll, so the only task post dll registration is to copy the pdb to the GAC directory.

Note: Copying the pdb may NOT be required with VS 2008 as it will look in the project debug directory for the pdb.



To copy the pdb, if required, to the gac you have various options some are listed below by my order of preference.

  1. Use the subst command to map a drive to the GAC

    • Type: Win + R > cmd > Enter

    • subst X: %windir%\assembly\gac_msil


    You should now have an X: drive pointing to your intermediate language assembly cache. Locate your dll directory and copy the pdb file.


  2. Use the copy command to copy your pdb file

    • Type: Win + R > cmd > Enter

    • copy <your_pdb_location> c:\windows\assembly\gac_msil\<your_dll>\<version>__<public_key>


    I create a post build event to accomplish this.


  3. Edit or rename the Desktop.ini file in c:\windows\assembly\

    • Type: Win + R > cmd > Enter

    • attrib c:\windows\assembly\desktop.ini -h -r -s

      rename c:\windows\assembly\desktop.ini desktop.dir


    You should now be able to browse the GAC directory.


  4. Disable cache viewer in the registry

    • Type: Win + R > regedit > Enter

    • create a new dword key under HKLM\Software\Microsoft\Fusion\ with the nane DisableCacheViewer and set it’s [DWORD] value to 1.

      Or you could also just change HKEY_CLASSES_ROOT\CLSID\{1D2680C9-0E2A-469d-B787-065558BC7D43}\Server\ default to xShfusion.dll or delete the value.


    You should now be able to browse the GAC directory.



Debugging

  1. Create a break point.

  2. Do an IIS reset, cos 90% of the time if you don't you'll crash IIS and VS.

  3. Open a SharePoint page you know uses the dll

  4. Attach the w3wp.exe process with your application user id to the debugger.

  5. Interact with the page until you reach your break point.

2 comments :