Andrew Connell [MVP MOSS]
1418 Posts |  40 Articles |  3755 Comments
.NET  |  MCMS  |  SharePoint  |  Office System
SharePoint Quick Links
Article Categories
Archives
Post Categories


Add to Technorati Favorites

I've long needed a single source to point people to when it comes to debugging and logging in SharePoint. I'm sure someone will say "oh look at my post" in a comment when this is read... please feel free to add comments to this post pointing to your debugging tricks.

When developers get tripped up with a nasty bug or something when building custom components in SharePoint, from Web Parts to server controls or even custom Features without a line of custom code (just loaded up with CAML)... well, effective debugging and logging can turn into being a developers best friend and get them out of a bind.

In my mind for you to be a SharePoint developer worth your pay, you must know how troubleshoot... heck... to be any kind of developer, you MUST know how to troubleshoot on your own. The trick is SharePoint can be quite daunting for those new to the platform and need a little help. Hopefully what follows will help you too!

Debugging Tips & Techniques

Attaching the debugger:
First and foremost, any SharePoint developer must be able to attach the Visual Studio debugger. Let's face it, unless you're using the VSeWSS or creating a workflow using Visual Studio 2008, F5 just doesn't work. You will have to manually attach the debugger. Well, it isn't that hard. Check out this post that shows you how to do it and also shows how to create a shortcut in Visual Studio.

Attaching the debugger to GAC'd assemblies:
"Why aren't my breakpoints being hit?!?!" Ever been there? Me too... what a PITA that is! What's going on? Well, the assemblies are in the GAC and the Visual Studio debugger can't see the debugging symbols (aka: *.pdb). Unless you've gone through the trouble of setting up a symbol store where all your PDBs are going, you'll need to put the debugging symbols in the same location as the assembly. The trick is finding the folder that contains your DLL in the GAC.

The c:\windows\assembly folder is not a real folder, it's a virtual folder. To get to the REAL folder, do the following:

  • Start » Run
  • %systemroot%\assembly\gac [ENTER]

This will open the GAC folder. Now, poke around until you find a folder that looks like this (you might need to jump up one folder and dive into the MSIL folder): [assembly file name -.DLL extention]\[assembly version in format of #.#.#.#]__[assembly public key token].

When you find that folder, open it up and you'll see your assembly. Copy the PDB file to that folder and then attach the debugger for some debugging joy!

Gimme my ASP.NET YSOD!
You've seen it... something errors out and all SharePoint says is "unknown error occurs." Great... thanks guys... about as helpful as "service engine soon" on my truck's dashboard. Arg! Not all errors are shown because that would be a security issue. So how do you get it? Just turn the callstack on and the custom errors off as shown in this post. Another awesome option is Ted Pattison's debugging Feature. Ted blogged it up here, but you can download it from his site here; you want the SharePointDebugger.zip file. This guy is a Web application scoped Feature that makes these changes for you.

Debugging Feature receivers & timer jobs:
These can be one of the toughest things to debug. They fire and sometimes are hard to catch or know if they blew past your breakpoint. "Am I even attached to the right process?" Even the most seasoned hit this. I've got a little trick I picked up along the way that helps. In my MSDN timer job article I show a technique of using an Assert (jump to the bottom, the section on Debugging Custom Timer Jobs). If you add the following code, a dialog will pop up on the server when it hits that line and will wait for you to address it:

  • System.Diagnostics.Trace.Assert(false)

That gives you plenty of time to attach the debugger to the right process.

Debugging tools:
Walk, don't run, and get the following:

  • Reflector: lets you peek into compiled assemblies.
  • DebugView: look at everything you emit in the debug statements.
  • Fiddler: HTTP debugging proxy letting you see all traffic on your machine.
  • SharePoint Manager 2007: Don't go in the database... use this guy to see everything in your farm!

Debugging resources:

Logging Tips

LogViewer Feature:
All those log files in the [..]\12\LOGS folder are hard to look at... what a pain to read! I know... go get a browser-based viewer snapin by Scot Hillier. This adds a new link to the Central Administration Operations page that lets you pick & filter the log files. Download it from the CodePlex Features project.

logiewer
Scot Hillier's LogViewer Feature

Throttle Logging:
Let's face it, if you are debugging, you're only interested in what happened in the last few seconds or minutes on your server. You don't need a ton of log files. Plus, you need them to be much more manageable. Go Central Administration » Operations » Diagnostic Logging. On this page you can set the number of log files to retain and how long each one should run. I set the values on my dev machines to only run for 3 minutes and keep the last 5 log files.

You can also turn on verbose logging... this will make the machine slow down a bit, but you'll get a TON of data. This is great for debugging problems with Feature activation... sometimes it even points to the specific XML/CAML node that's causing the issue! Just a word of warning... don't leave verbose enabled on your production box... SharePoint turns into one chatty app and those log files fill up! But more data points is always better than less when debugging!

logs
How I like to setup my logging when I'm troubleshooting on a development machine.

Hope this helps!

posted on Wednesday, June 11, 2008 5:07 PM

Feedback

 re: SharePoint Debugging and Logging Tips and Tricks 6/11/2008 6:00 PM Ted
Gravatar AC:

I was having a heck of a time debugging features I was activating through STSADM until I found I could use:

System.Diagnostics.Debugger.Launch()

which would immediately prompt me for my debugger. I just grab my open project and voila! I'm debugging my receiver.

found it on:

http://dotnetmafia.com/blogs/dotnettipoftheday/archive/2008/04/01/debugging-a-feature-when-using-stsadm-exe.aspx

 re: SharePoint Debugging and Logging Tips and Tricks 6/11/2008 6:21 PM Ted
Gravatar One more pointer:

I've discovered when I'm debugging a dll in the GAC, I used to drop the .pdb in there as you've described.

Since then, I've started using Debug->Windows->Modules after attaching to the process in Visual Studio to examine the loaded .pdb's, locating the one for my dll, then using it to Load the .pdb.

Hope that helps.

 re: SharePoint Debugging and Logging Tips and Tricks 6/12/2008 12:35 PM Doug Perkes
Gravatar Also note that if you are using Visual Studio 2008 you don't need to worry about the PDB files, even if the assemblies are in the GAC. I also like to use a simple Visual Studio add-in for determining the process id to attach to. I've documented how to do this here:
http://www.azsharepointpros.com/ShareAndEnjoy/Lists/Posts/Post.aspx?ID=7

 re: SharePoint Debugging and Logging Tips and Tricks 6/12/2008 2:54 PM Kevin Davis
Gravatar Andrew,
Thanks for the tip, the logging view is awesome. I have had the real fun of looking through the logs, trying to discover why my users cannot check out documents.

Aloha,

Kevin


# re: SharePoint Debugging and Logging Tips and Tricks 6/12/2008 7:26 PM Gavin
Gravatar I've allways just had a post build script that uses GACUTILS to install my assemblies to the GAC (after removing the old ones)

After which I just attach my debugger and I'm golden.

# re: SharePoint Debugging and Logging Tips and Tricks 6/12/2008 11:23 PM AC [MVP MOSS]
Gravatar These are fantastic comments... keep it up!!!

 re: SharePoint Debugging and Logging Tips and Tricks 6/16/2008 10:24 AM zed
Gravatar -AC,
I do not understand how it works without putting the .pdb in the GAC folder. Somehow VS connects the .pdb to the code running from the GAC in SharePoint. Its a mystery to me. Somethings we never truly understand. Look forward to receving your new book.

# re: SharePoint Debugging and Logging Tips and Tricks 6/26/2008 5:21 AM derek
Gravatar Security holograms
Security bags

# re: SharePoint Debugging and Logging Tips and Tricks 6/28/2008 11:40 PM Michhes
Gravatar MOSS logs a fair whack of information to the Windows Event Viewer (the Application log). I often find more complete stack traces in there, even with the callstack on and custom errors off. Also useful for production environments.

# re: SharePoint Debugging and Logging Tips and Tricks 11/4/2008 6:41 AM John
Gravatar Thanks for the info!
Excellent article, added to bookmarks.

Post Feedback

Title:
Name:
Email:
(email will not be displayed)
Url:
Comments: 
Please add 1 and 2 and type the answer here:    
All Comments Are Filtered & Moderated
Unfortunately comment spammers are just too effecient and are constantly dirtying up blogs with irrelevant and unwanted comments trying to improve their standing on search engines. All comments on this blog are moderated. I do not censor comments, but I don't approve comments with vulger language or those soliciting products. Most of the time comments are approved within a few hours of being submitted with the only exception when I'm traveling.

Why are you asking for my email address?
The only reason I'm asking for your email address, which isn't required to submit a comment, is to provide a gravatar if you've created an account for yourself and associated your email address with a small image. If you have a gravatar created for the email address you submit, it will appear next to your comment. Otherwise nothing will appear.

What is a gravatar?
A gravatar is a "globally recognized avatar." You can get more information about gravatars, as well as create your own for free, at www.gravatar.com. You can also view my gravatar here.


Copyright © 2003 - 2009 Andrew Connell
Creative Commons License 
This work is licensed under a Creative Commons License
Site design by Heather Solomon.

 
 
MOSS WCM Training
Looking for MOSS 2007 WCM developer training? Look no further! I teach my 4-day hands-on and 5-day online WCM classes for developers I offer through the Ted Pattison Group.

Get more information on the WCM courses!


Upcoming Classes
 Hands-on WCM:
 » Las Vegas, NV
   April 20-24, 2009
 Online WCM:
 » Feb 9-13, 2009


» Register today!

JAX Office Geeks
Jacksonville Office Geeks (JOG)
JOG is a special interest group in Jacksonville, FL dedicated to bringing the local SharePoint commnity together to share tips, tricks, ideas and best practices for developing solutions on the SharePoint platform.

Next meeting details...
When:
Thur. Feb 19th, 2008
  6-8p EDT
Topic:
Cheap and Easy Wildcard Search

Speaker:
Becky Isserman

RSVP Today!


» Subscribe to the JOG newsletter