How to put PDBs in the GAC
This TLA (Three Letter Acronym) littered post is about how to add PDB (Program DataBase) files to the GAC (Global Assembly Cache).
Today my current client had the need to get the true source of an exception. They had a catch statement which logged the exception (via log4net) to a file, but the location in question was a poorly designed component with hundreds of lines of code all wrapped within a very large Try-Catch which logged errors. The error was likewise unhelpful as to the source because it was an array out of bounds exception, and this code did alot of string array manipulation. The solution was clear to me, we needed to load the PDB files onto the server so that when an exception was thrown there would be line number information to go with it.
The problem? The assembly was being called by BizTalk Server and as such it was strongly named and in the GAC.
The solution? Add the PDB files to the GAC, of course.
The Global Assembly Cache which is located at %WINDIR%\assembly ("c:\windows\assembly" on most boxes) is in fact organized into many different directories all of which exist under %WINDIR%\assembly but which by default are hidden from view by Explorer. Fortunately, the command prompt does not suffer the same problems. If you open a command prompt and "cd %windir%\assembly" and do a "dir" you will see several directories as you can see in the first image.
If you change directory to "GAC" you will see a directory for every single assembly in the GAC. From here, cd to the directory for the assembly you want, in my example nunit.framework, and you will see another interesting set of directories. Here you will see one directory for every combination of version number and public key in the GAC. You need to know what version you are working with, and the public key for that. cd into that directory and you will find a copy of your assembly. Now all you have to do is copy your PDB file to this location and your next exception should contain line numbers for the offending code.
Since the work to generate line numbers is only done when an exception is being thrown there is little to no reason not to include the PDB files in all your production deployments to the GAC. Yes, generating them takes time, but if you're throwing an exception this shouldn't be a problem. After all, you are treating exceptions as exceptional, right?