Dedicated to development, configuration, and tips and tricks for both WSS 3.0 and MOSS

The Mysteries of the GAC

Posted by Brian LaSitis on Tuesday, 27 Jan 2009 02:10

For most production SharePoint deployments that involve custom .NET code, such as custom developed web parts, controls, event handlers, etc., best practice dictates that any shared assemblies should be deployed to the Global Assembly Cache (GAC).  While this is a great practice, the GAC location (e.g. %WINDIR%\Assembly) does not behave like a typical folder, or at least doesn’t appear to, and for most .NET developers, the GAC in general is somewhat of a mystery.  One of the biggest perplexities with the GAC is that upon first glace, there does not seem to be a means for retrieving a copy of an assembly that is deployed to the GAC.  While all of us have probably dragged a .NET assembly into the %WINDIR%\Assembly folder to add it to the GAC, if you try dragging an item out of the GAC, it does nothing, and the familiar Cut/Copy/Paste operations that are standard on any Windows Explorer folder view are grayed-out.  How dare you do this to us Microsoft?!

In the sections below I will explain how you can retrieve the actual DLL for an assembly that is only deployed within the GAC, and in the process, we will make some sense out of how the GAC actually works and see how it really is just a specialized folder hierarchy for storing .NET assemblies.

The Uniqueness of the %WINDIR%\Assembly Path Location

If you open a Windows Explorer to the %WINDIR%\Assembly path location, you are presented with a specialized view of this folder, as shown below:

image

This unique view is the result of a Windows Shell extension called SHFusion.dll (as an aside, the reason for this name is the original codename for the GAC, when the .NET Framework was first being developed, was Fusion).  However, if you open a Command Prompt and switch to the %WINDIR%\Assembly path, you see a slightly different listing:

image

The reason for the Command Prompt displaying this view, as opposed to what Windows Explorer shows, is that Windows Shell extensions are not applied to file operations performed from the Command Prompt.  Here we are presented with seven (7) folders, each of which is explained below:

  • GAC – stores .NET 1.x assemblies
  • GAC_32 – stores .NET 2.x+ assemblies that are built specifically for 32-bit architecture.
  • GAC_MSIL – stores .NET 2.x+ assemblies that are architecture independent, meaning they can be used on 32- or 64-bit systems.
  • NativeImages_Vx_Architecture – there can be multiple folders of this format, specific to each version of the .NET Framework present on the system, with possible 32 and 64 bit flavors of each.  Each of these folders is used for storing native images of .NET assemblies that have been pre-compiled using NGen, to eliminate the need to run the MSIL code through the JIT compiler at execution time.
  • temp, tmp – temporary folders.

Additionally, on a 64-bit system, one additional folder would be present:

  • GAC_64 – stores .NET 2.x+ assemblies that are built specifically for 64-bit architecture.

To determine which folder the assembly you seek is within (e.g. GAC, GAC_32, or GAC_64), refer to the Processor Architecture column within the Fusion-based Windows Explorer view.  Let us consider an example:

Assume we would like to retrieve the DLL for the Contoso.Website.Controls assembly, shown in the Explorer view above.  As we can see, the Processer Architecture indicated is MSIL, indicating that this assembly will be within the GAC_MSIL subfolder, if we proceed to descend into that level, we see the following:

image

At this level, we have a subfolder for each assembly, so let us descend into the Contoso.Website.Controls subfolder, to see the following:

image

At this level, we see folders with names based upon the version of the assembly, culture (if not invariant), and public key token.  It is this exact folder structure the enables the GAC to store multiple versions of the same assembly without one overwriting or conflicting with the other.  Since there is only one subfolder present at this level, let us proceed to descend into it, to see the following:

image

Voila!  At this level, we are able to take a copy of the exact DLL file that was deployed to the GAC.  What was a pleasant surprise to me is that the GAC does not in any way mangle the original name of the DLL that was deployed.

Disabling the SHFusion.dll Shell Extension

There is another option of seeing the actual folder structure of the GAC that does not involve the command-line, but I would not recommend doing this on a production system.  To view the same folder structure within Windows Explorer that we were able to navigate through using the Command Prompt, we can disable the SHFusion.dll shell extension using one of three possible methods:

  1. Rename %WINDIR%\Assembly\Desktop.ini – within %WINDIR%\Assembly, a hidden, read-only, system attributed file named Desktop.ini is present.  By renaming this file to something else, such as Desktop.ini.bak, we effectively prevent SHFusion.dll from loading for this folder.
  2. Add the DisableCacheViewer Registry Value – within the HKLM\Software\Microsoft\Fusion registry path, a new DWORD value can be created with the name DisableCacheViewer and a value of 1 to prevent SHFusion.dll from being loaded.
  3. Rename SHFusion.dll – the SHFusion.dll itself can be found within %WINDIR%\Microsoft.NET\Framework\v.XX, and if this file is renamed, it will not be loaded when Windows Explorer is pointed at the %WINDIR%\Assembly path.

By performing any one of the above steps, upon opening %WINDIR%\Assembly the next time, you will be presented with the following view, similar to what we saw within the Command Prompt dir listing above:

image

So there you have it – the biggest mysteries of the GAC have all been dispelled:  how its path location works within Windows, its unique rendering method within Windows Explorer, how it actually stores DLLs you deploy to it, and how you can retrieve them later.  So in reality, all the GAC truly is made up of is a specialized folder hierarchy for tracking multiple versions of assemblies, independent of processor architecture, that has special .NET CAS policies defined for it to allow assemblies deployed to this location to have Full Trust permissions.  Now go forth, fire up your compilers, and start deploying code to the GAC!

Posted by Brian LaSitis | 0 Comments | Trackback Url | Bookmark with:        
Categories: .NET

Links to this post

Trackback from wss.made4the.net: by Jeremy Thake on 20 Feb 2009 02:43

Trackback from Casino 1242955280 on 21 May 2009 08:35

Trackback from sdiywhir on 22 May 2009 08:15

Trackback from Casino 1243045918 on 22 May 2009 10:14

Trackback from Casino 1243052402 on 22 May 2009 11:52

Trackback from Casino 1243056365 on 23 May 2009 12:47

Trackback from Casino 1243115379 on 24 May 2009 01:12

Trackback from Casino 1243365450 on 29 May 2009 10:49

Trackback from txjrzlwq on 18 Jul 2009 10:18

Trackback from qkktivql on 20 Jul 2009 12:34

Trackback from vlydbsur on 23 Jul 2009 08:52

Trackback from fwiskcjg on 23 Jul 2009 09:15

Trackback from jedoifyi on 23 Jul 2009 10:23

Trackback from nnpjqhzb on 23 Jul 2009 10:58

Trackback from urpxurhq on 23 Jul 2009 11:54

Trackback from ijsewbcq on 24 Jul 2009 01:11

Trackback from mexxkijt on 31 Jul 2009 07:15

Trackback from qigyihzt on 06 Aug 2009 01:37

Trackback from Casino 1249772306 on 09 Aug 2009 12:05

Trackback from Casino 1249883930 on 12 Aug 2009 11:16

Trackback from Casino 1250191482 on 14 Aug 2009 06:00

Trackback from Casino 1250533814 on 17 Aug 2009 02:26

Trackback from Casino 1250538984 on 17 Aug 2009 02:53

Trackback from Casino 1250624386 on 18 Aug 2009 02:25

Trackback from Casino 1250625839 on 18 Aug 2009 02:47

Trackback from Casino 1250627697 on 18 Aug 2009 04:38

Trackback from Casino 1250633977 on 18 Aug 2009 05:24

Trackback from Casino 1250699013 on 19 Aug 2009 12:21

Trackback from Casino 1250722054 on 19 Aug 2009 09:04

Trackback from jwgvubpq on 29 Aug 2009 04:07

Trackback from jwgvubpq on 29 Aug 2009 04:07

Trackback from chagfpfa on 12 Feb 2010 10:15

Trackback from download skins for windows media player on 03 Mar 2010 04:33

Trackback from cialis discount on 15 Mar 2010 08:08

Trackback from health benefits of low dose cymbalta on 16 Mar 2010 05:34

Trackback from buying cialis online uk on 16 Mar 2010 05:41

Trackback from cheap cialis on 16 Mar 2010 06:25

Trackback from viagra bestellen online on 16 Mar 2010 06:47

Trackback from cheapest generic cialis in Surry VA 23883 Virginia on 16 Mar 2010 06:52

Trackback from viagra billig bestellen on 16 Mar 2010 07:07

Trackback from cialis online pharmacy 100/100mg pills $1.35 each on 16 Mar 2010 07:33

Trackback from best time to take lexapro 50mg on 16 Mar 2010 07:47

Trackback from swedish to english translation on 19 Mar 2010 07:26

Trackback from plzqfooh on 24 Mar 2010 06:56

Trackback from oajvoyqs on 24 Mar 2010 09:14

Trackback from apcidswg on 24 Mar 2010 09:31

Trackback from qqxseqzr on 26 Mar 2010 09:42

Trackback from kuzyapyp on 27 Mar 2010 12:17

Trackback from wulhzgam on 27 Mar 2010 12:54

Trackback from asnzcawn on 27 Mar 2010 03:07

Trackback from phawtaao on 27 Mar 2010 03:58

Trackback from krlxhmmd on 27 Mar 2010 07:42

Trackback from Casino 1269728909 on 27 Mar 2010 06:55

Trackback from Casino 1269728908 on 27 Mar 2010 06:55

Trackback from Casino 1269729422 on 27 Mar 2010 06:55

Trackback from likxjneq on 27 Mar 2010 08:53

Trackback from Casino 1269771703 on 28 Mar 2010 11:30

Trackback from Casino 1269771815 on 28 Mar 2010 11:30

Trackback from Casino 1269772318 on 28 Mar 2010 11:52

Trackback from wuohmzno on 31 Mar 2010 11:12

Trackback from Casino 1270230446 on 02 Apr 2010 03:51

Trackback from Casino 1270231741 on 02 Apr 2010 03:51

Trackback from Casino 1270232424 on 02 Apr 2010 03:51

Trackback from Casino 1270494559 on 05 Apr 2010 06:20

Trackback from Casino 1270493914 on 05 Apr 2010 08:57

Trackback from aofgypti on 06 Apr 2010 11:20

Trackback from cheap cialis on 16 Apr 2010 03:20

Trackback from faxless easy online payday loans on 16 Apr 2010 03:20

Trackback from buy cipro 250mg in Valley springs SD 57068 South Dakota on 05 May 2010 08:04

Trackback from Casino 1273771865 on 13 May 2010 04:51

Trackback from Casino 1273771396 on 13 May 2010 06:34

Trackback from Casino 1273771956 on 13 May 2010 06:34

Trackback from Casino 1273772417 on 13 May 2010 06:34

Trackback from Casino 1273772500 on 13 May 2010 11:24

Trackback from Casino 1273971839 on 16 May 2010 01:25

Trackback from Casino 1274018354 on 16 May 2010 10:30

Trackback from Casino 1274180235 on 18 May 2010 07:03

Trackback from Casino 1274178521 on 18 May 2010 07:35

Trackback from Casino 1274179362 on 18 May 2010 08:31

Trackback from Casino 1274311448 on 19 May 2010 10:05

Trackback from Casino 1274433794 on 21 May 2010 06:43

Trackback from Casino 1274566454 on 23 May 2010 04:49

Trackback from Casino 1276648322 on 15 Jun 2010 11:23

Trackback from Casino 1276643979 on 15 Jun 2010 11:23

Trackback from Casino 1276644814 on 15 Jun 2010 11:23

Trackback from Casino 1276715057 on 16 Jun 2010 06:08

Trackback from Casino 1276717002 on 17 Jun 2010 12:48

Trackback from Casino 1276953490 on 19 Jun 2010 11:22

Trackback from Casino 1277139884 on 21 Jun 2010 01:07

Trackback from Casino 1277214763 on 22 Jun 2010 10:57

Trackback from Casino 1277306709 on 23 Jun 2010 01:08

Trackback from Casino 1277733784 on 28 Jun 2010 01:43

Trackback from Casino 1280331167 on 28 Jul 2010 02:00

Trackback from Casino 1280345989 on 28 Jul 2010 06:13

Trackback from Casino 1284491528 on 14 Sep 2010 05:15

Trackback from Casino 1287050304 on 14 Oct 2010 07:36

Trackback from Casino 1290150433 on 19 Nov 2010 04:17

Trackback from Casino 1290852380 on 27 Nov 2010 07:30

Trackback from Casino 1292243887 on 13 Dec 2010 10:10

Trackback from Casino 1297161962 on 08 Feb 2011 08:11

Trackback from Casino 1299680089 on 09 Mar 2011 01:23

Trackback from commander viagra on 29 Jan 2012 04:24

Trackback from nymphomax on 04 Feb 2012 04:54

Trackback from mujeres para hacer el amor on 18 Feb 2012 12:49

Trackback from free penis pills on 19 Feb 2012 04:55

Trackback from posters printing on 21 Feb 2012 07:44

Trackback from First Date Guides on 21 Feb 2012 08:24

Trackback from estrogen on 23 Feb 2012 09:12

Trackback from The most successful Is WHAT Website on 26 Feb 2012 07:42

Trackback from receive outlook on 02 Mar 2012 03:30

Trackback from posters printing on 02 Mar 2012 08:38

Trackback from autism treatments on 03 Mar 2012 09:56

Trackback from The friendliest WORKFLOW Website on 04 Mar 2012 05:28

Trackback from auto insurance on 04 Mar 2012 12:41

Trackback from my articles on 06 Mar 2012 06:07

Trackback from bingo cams on 07 Mar 2012 07:40

Trackback from printing posters on 07 Mar 2012 09:20

Trackback from dj table on 08 Mar 2012 12:07

Trackback from lion king broadway tickets on 09 Mar 2012 07:40

Trackback from Zestril side effects, Side Effects of Zestril, Zestril on 09 Mar 2012 10:56

Trackback from legal herb shop on 10 Mar 2012 05:46

Trackback from synchronize on 10 Mar 2012 08:01

Trackback from political postcards printing on 10 Mar 2012 09:28

Trackback from mortgage loans calculator on 17 Mar 2012 06:16

Trackback from Backlink on 19 Mar 2012 03:39

Trackback from revista online on 21 Mar 2012 06:06

Trackback from lion king broadway tickets on 22 Mar 2012 07:44

Trackback from Medigap Insurance on 27 Mar 2012 09:44

Trackback from Online coupon clipping service on 30 Mar 2012 02:29

Trackback from powerful print audit tool on 31 Mar 2012 10:19

Trackback from get car insurance quote online on 06 Apr 2012 05:12

Trackback from popcorn calories on 11 Apr 2012 08:24

Trackback from cheapest car insurance guaranteed on 13 Apr 2012 11:27

Trackback from Online coupon clipping service on 13 Apr 2012 11:29

Trackback from car insurance quotes on 15 Apr 2012 09:18

Trackback from car insurance quotes on 15 Apr 2012 10:47

Trackback from Peliculas Online on 17 Apr 2012 07:13

Trackback from website promotion on 20 Apr 2012 06:43

Trackback from programa de gestion prestashop on 23 Apr 2012 05:15

Trackback from gold forum on 23 Apr 2012 05:40

Trackback from juegos gratis on 24 Apr 2012 03:00

Trackback from canciones online on 24 Apr 2012 10:50

Trackback from learn spanish verbs first on 27 Apr 2012 10:35

Trackback from audio books to learn spanish for children on 27 Apr 2012 03:10

Trackback from canciones online on 30 Apr 2012 01:05

Trackback from jugar gratis on 04 May 2012 04:21

Trackback from direktimport auto on 04 May 2012 02:37

Trackback from hgh benefits on 04 May 2012 11:46

Trackback from short term loan on 06 May 2012 05:15

Trackback from payday advances on 08 May 2012 02:39

Trackback from short term loan on 08 May 2012 01:45

Trackback from buy hgh on 11 May 2012 10:49

Trackback from Custom Facebook Fan Page on 11 May 2012 08:47

Trackback from חשבונית לעוסק פטור on 12 May 2012 08:22

Trackback from read more on 13 May 2012 02:48

Trackback from vitamin a cream for face on 15 May 2012 11:08

Trackback from cancionesonline.net on 16 May 2012 02:46

Trackback from bridging finance on 16 May 2012 08:43

Comments



Name

Url

Email

Comments

CAPTCHA Image Validation