Dvolution

Debugging SharePoint Events

Seeing as how I’ve kept myself busy with SharePoint recently and had to make an event handler that ran some code when a new SPListItem was added. I ran into issues but had no idea where they were coming from. I tried a heck of a lot of debug methods but none made me any wiser. Then I bumped into this article which describes how you can single-step through event handler code.

This is how you pull it off:

  1. Compile your event handler in debug mode.
  2. Open the GAC (Global Assembly Cache) or navigate to “C:\Windows\Assembly”.
  3. Register your event handler with the server (you only have to do this once).
  4. Open your explorer and find your assembly. Default is your binDebug folder in your project folder.
  5. Drag and drop your assembly into the GAC.
  6. Map your GAC folder so that it doesn’t open in the non-standard Explorer view it normally opens under. A nice trick to use is to use the following:
    • Open a command window
    • Type: “subst G: C:\Windows\Assembly”
    • This will map the GAC folder to a new driveletter (G: in this case). You might have to change this if you already have a G: drive on your system.
  7. Open G:/ and go to the GAC_MSIL folder.
  8. There’s a folder here that has the same name as your assembly. Open that up and it should contain your DLL file (it might contain subfolders representing the DLL version and it’s public key).
  9. Copy the .pdb file of the assembly into the folder in the previous step. The .pdb file is also located in your project’s binDebug folder.
  10. Perform an IISReset, to make sure everything goes as you want it to go.
  11. Open your Visual Studio and put some breakpoints where you want them to be.
  12. Attach the debugger to the w3wp.exe process. This can be done by going up to Tools > Attach to process.
  13. Now go to your SharePoint site and perform the action that triggers the event handler.

You should now hit the breakpoints you placed in your code. Then you can single step through your code to find out where your error came from!

Steven is een afgestudeerd Software Engineer en heeft een baan als .NET ontwikkelaar. Fan van wielrennen, doet zelf aan mountainbiken, speelt wanneer hij zin heeft op zijn gitaar en Xbox 360. Probeert met enige regelmaat te bloggen over vanalles en nog niets.

3 reacties op “Debugging SharePoint Events”

  1. is it working for anyone? not in may case… :o (

  2. Works perfectly for me. I’ve also used the same technique to debug other SharePoint things deployed to the GAC. What is going wrong? Are you not hitting any breakpoints or?

  3. Excellent Post!!

Ik heb iets te zeggen!

Debugging SharePoint Events