Skip to main content

Elumenotion Blog

Go Search

 
Elumenotion > Elumenotion Blog > Posts > You Don't Need to Copy PDB Files to Debug in the GAC!
You Don't Need to Copy PDB Files to Debug in the GAC!

Following up on my last post, many developers choose to put assemblies into bin because they find them easier to debug. Usually, they do not create detailed CAS policies. Instead they simply set the trust level to full so they can 'just make it work'. While this is a sentiment I can fully understand having wrestled with it myself, it's not the best idea. Generally, I think most will agree that the closer the development environment's configuration matches the production environment the better. So developing with assemblies in BIN with the web config set to full trust and then deploying them at the last minute to the GAC just makes me feel unclean.

Fortunately, it's just as easy to debug in the GAC as it is in BIN if you configure the development environment correctly. Unfortunately, few know how to do this because the internet is polluted with pages full of bad information that is a held over from previous versions of .Net. You can spot these easily because they will say you need to copy the debug symbols (.pdb file) to the GAC. In and of itself, that will not work. These days it is also completely unnecessary.

To configure VS 2005 to debug the assemblies properly, do the following:

Open Tools | Options.

Check Show all settings if needed and locate Enable Just My Code (Managed only)

Uncheck it and click OK

Attach to the w3wp.exe process for the instance you want to debug.

There may be more than one. You can attach to all of them, but only the first one will be debugged. To verify that you are attached to the correct instance of w3wp.exe, open the Modules window by pressing CTRL-ALT-U.

If your assembly is listed, you picked the right one. If not, choose stop and attach to the next one until you find it.

In this example, the assembly is loaded. Note that the symbol file is loaded and that it was not copied to the GAC.

My breakpoints are hit! Yay!

 

P.S. Don't forget the set debug="true" in the web.config or it won't matter where you put the assembly! This can really trip you up if you forget to do it because the breakpoints will turn all nice and red, but it won't stop.

Note: I renamed this post because I want people to read it and I decided that some might miss the message based on the earlier title.

Comments

Symbol Caching and Search Folders

You can also configure a symbol server or search paths, and alter your build process to publish the PDB files out to the symbol server or cache directory. Then you can always have symbol information available, no matter what version of the assembly happens to be loaded (very useful for troubleshooting a production or QA environment problem where you otherwise might not have retained the pdb files). It's easily configured through the Symbols section under Debugging in the VS Options dialog.

This can also be very handy for team development scenarios where one developer is building assemblies that are used by others who do not necessarily have the proper PDB files available to them without a central repository.
Dan Attis at 11/16/2007 4:24 PM

Very True!

Lol! There goes my follow up post. :)
Just kidding. Those are great points Dan!
Doug Ware at 11/16/2007 8:13 PM

PingBack from http://drewmace.blogspot.com/2007/11/debugging-from-gac.html

Good article.
http://drewmace.blogspot.com at 11/21/2007 11:55 AM

Thanks!

This is a Godsend in SharePoint, where GAC deployment is generally the way to go. I'll have to come up with a good topic for follow-up with respect to feature/solution development, as supportability is a *HUGE* concern for my clients. http://www.thomascarpe.com/ Cheers!
Thomas Carpe at 12/11/2007 2:47 PM

Does it work for remote debugging?

Hi,
I tried your methods for debugging a remote MOSS server but when no symbol was loaded for the DLL i was trying to debug.

I tried to load the symbol by pointing to a PDB file on my local machine, but VS2005 keep saying the "The symbol file <assembly>.pdb does not match the module".

Only when i copied the PDB to the c:\windows\assembly on the remote server did i finally can get the symbol loaded.

How can I debug remotely without copying the PDB to GAC?

Thanks.
Anon at 5/14/2008 4:57 AM

Pingback from http://coderjones.blogspot.com/2008/08/debugging-moss-workflows.html

Thanks for this information!  I have linked back and suggested anyone who reads my blog to check this out.
Jeremiah at 8/17/2008 9:34 PM

re: Does it work for remote debugging?

for remote debugging i manualy put the pdb files into "c:\windows\dll\"

pro:
- u don't need to now the full GAC Name with version number/pkey a.s.o.
- it workx :)

btw: to copy the dll remotly into the gac with "Post-Build Event", use remcom.exe -> http://talhatariq.wordpress.com/projects/remote-command-executor-xrce/
dataCore at 9/23/2008 11:31 AM

You, my friend, get a gold star!

I've been using www.codeplex.com/STSDev (great tool, BTW)  and trying to get debugging to work with MOSS Web Parts.  I've been chasing my tail in circles.  I've tried everything that I've found and nothing worked until now.

I tried this and it worked right away!

You get a Gold Star!  Actually, you get two Gold Stars!

Cheers!
Mark DiGiovanni at 9/24/2008 11:17 PM

Thanks!

Worked great. This was a big help.
Anon at 10/3/2008 2:50 PM

Thank you

I have been trying for two days now to get this to work. Your blog made my day! I will make sure to bookmark it carefully.
Joan at 1/30/2009 4:35 AM

It Works

Thanks man
it works with VS08

but the thing u need to add the assembly manully
and restart the iis
then attach the process
ashraf at 2/10/2009 2:44 PM

Thanks

I was trying like hell for 2 hrs to find debugging techniques for the assembly in gac. It worked out .
Prabin at 2/12/2009 7:57 PM

this works only if i add the dll from obj\debug to the gac

any reason behind this
sundar at 2/17/2009 2:38 AM

Neha Saluja

This was truely gr8 hidden information unrevealed :)
Anon at 4/21/2009 4:14 AM

Re: You Don't Need to Copy PDB Files to Debug in the GAC!

Was truely gr8!!
Neha at 4/21/2009 4:15 AM

Man, you deserve an Nobel price...

Thank you dude. This is really something useful for humanity... Hehehehee... BIG THANKS AGAIN!
khovanskiiªn at 4/22/2009 5:45 PM

Greaaaaaaaaaaaaaaaaaaaaaaat

thanks alot that really helps! keep it up! thanks again :)
Rayyan at 9/4/2009 2:39 AM

iisapp to get the correct process id

Awesome info, thanks a bunch! I just wanted pass along you can also get the correct w3wp.exe process id by running iisapp from a command prompt.  It should give you the name of the web site and it's process id.
Darryl Dalton at 10/22/2009 3:57 PM

This post is not completely clear

Hi,

I am using Visual Studio 2008. I have a .dll and .pdb files.

1. I opened Visual Studio.
2. Created a new project.
3. Unchecked Enable Just My Code in Tools->Options.
4. Pressed CTRL + ALT +U. Modules windows opened.
5. I ran my application (which I want to debug and for which i have dll and pdb files). Now I attached w3wp.exe and I can see all my dlls and pdb files are in the list.
6. What next ? How can I see the code? And how I can put the breakpoint?

Something am I missing here.

Please provide more details.
Sreedhar at 1/8/2010 12:29 PM

Why is Sharepoint so painful!?

It seems everything in Sharepoint is just painful or like butchering instead of programming, got stuck on debugging using WSPBuilder  but this is the way to go for sure to ease some of that pain.  Thanks! http://www.ifunky.net
Dan at 3/9/2010 6:46 AM

You R Gr8

You R Gr888888888888!!!!
Anon at 3/31/2010 8:31 PM

Couldnt be better

need i say more
Anon at 4/19/2010 6:29 AM

Without disabling Just My Code?

The "Just My Code" option claims to optimize assembly loading.  I'm working on a *very* large project and am paranoid about disabling any optimization features.

In my case, to solve this problem I copy the .pdb and the .DLL generated in the bin folder to this folder:
C:\Users\xxxxx\AppData\Local\Temp\Temporary ASP.NET Files\xxxxx\assembly\dl3\xxxxx

This seemed to be a temporary fix.  It worked for days, but when I came in the next week, the folder had the singular .DLL and no .pdb (again).  Is there a way to force VS to output these correctly, or is the optimization so insignificant that I can deal with it?
BSG at 7/13/2010 7:44 PM

Add Comment

Items on this list require content approval. Your submission will not appear in public views until approved by someone with proper rights. More information on content approval.

Title


Body *


Your Name *


Attachments
Follow me on twitter!
  Archive
  Archive (Calendar)
  Skinner Created Themes
  New Skinner Download
  New Skinner Tutorial

©  2009 Elumenotion, LLC  |   SharePoint Training, SharePoint Consulting and SharePoint Staffing
8075 Cavendish Place | Suwanee, Georgia 30024 | + 1 (888) 653-5021