Global Assembly Cache


The global assembly cache is, as the name implies, a cache for globally available assemblies. Most shared assemblies are installed inside this cache, but some private assemblies can also be found there. If a private assembly is compiled to native code using the native image generator, the compiled native code goes into this cache, too!

This section explores creating native images at installation time and viewing shared assemblies with the Global Assembly Cache Viewer and the Global Assembly Cache Utility.

Native Image Generator

With the native image generator, Ngen.exe, you can compile the IL code to native code at installation time. This way the program can start faster because the compilation during runtime is no longer necessary. The ngen utility installs the native image in the native image cache. The physical directory of the native image cache is <windows>\assembly\NativeImages<RuntimeVersion>.

With ngen install myassembly, you can compile the MSIL code to native code and install it into the native image cache. This should be done from an installation program if you would like to put the assembly in the native image cache.

With ngen you can also display all assemblies from the native image cache with the option display. If you add an assembly name to the display option you get the information about all installed versions of this assembly and the assemblies that are dependent on the native assembly:

 C:\> ngen display System.Windows.Forms Microsoft (R) CLR Native Image Generator – Version 2.0.50727.312 Copyright (C) Microsoft Corporation 1998-2002. All rights reserved. NGEN Roots: System.Windows.Forms, Version=2.0.0.0, Culture=Neutral, PublicKeyToken=b77a5c561 934e089, processorArchitecture=msil NGEN Roots that depend on "System.Windows.Forms": ComSvcConfig, Version=3.0.0.0, Culture=Neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=msil ehepg, Version=6.0.6000.0, Culture=Neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=msil ehepgdat, Version=6.0.6000.0, Culture=Neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=msil ehExtCOM, Version=6.0.6000.0, Culture=Neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=msil ehexthost, Version=6.0.6000.0, Culture=Neutral, PublicKeyToken=31bf3856ad364e35,  processorArchitecture=msil ehRecObj, Version=6.0.6000.0, Culture=Neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=msil ehshell, Version=6.0.6000.0, Culture=Neutral, PublicKeyToken=31bf3856ad364e35, p rocessorArchitecture=msil EventViewer, Version=6.0.0.0, Culture=Neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=msil

If the security of the system changes, it’s not sure if the native image has the security requirements it needs for running the application. This is why the native images become invalid with a system configuration change. With the command ngen update all native images are rebuilt to include the new configurations.

With the installation of the .NET 2.0 runtime the Native Image Service (or the Window Service CLR Optimization Service) with the name Microsoft .NET Framework NGEN v2.0.50727_X86 is installed. This service can be used to defer compilation of native images and regenerates native images that have been invalidated.

The command ngen install myassembly /queue can be used by an installation program to defer compilation of myassembly to a native image using the Native Image Service. ngen update /queue regenerates all native images that have been invalidated. With the ngen queue options pause, continue, and status you can control the service and get status information.

Global Assembly Cache Viewer

The global assembly cache can be displayed using shfusion.dll, which is a Windows shell extension to view and manipulate the contents of the cache. A Windows shell extension is a COM DLL that integrates with Windows Explorer. You just have to start Explorer and go to the <windir>/assembly directory.

Figure 16-15 shows the Assembly Cache Viewer.

image from book
Figure 16-15

With the Assembly Cache Viewer, you can see the global assembly name, type, version, culture, and the public key token. Under Type you can see if the assembly was installed using the native image generator. When you select an assembly using the context menu, it’s possible to delete an assembly and to view its properties (see Figure 16-16).

image from book
Figure 16-16

You can see the real files and directories behind the assembly cache by checking the directory from the command line. Inside the <windir>\assembly directory, you can find multiple GACxxx directories and a NativeImages_<runtime version> directory. The GACxxx directories contain shared assemblies. GAC_MSIL contains the assemblies with pure .NET code; GAC_32 contains the assemblies that are specific to a 32-bit platform. On a 64-bit system, you can also find the directory GAC_64 with assemblies specific for 64 bit. The directory GAC is for versions of the framework previous to .NET 2.0. In the directory NativeImages_<runtime version>, you can find the assemblies compiled to native code. If you go deeper in the directory structure, you will find directory names that are similar to the assembly names, and below that a version directory and the assemblies themselves. This allows the installation of different versions of the same assembly.

Global Assembly Cache Utility (gacutil.exe)

The assembly viewer can be used to view and delete assemblies with Windows Explorer. gacutil.exe is a utility to install, uninstall, and list assemblies using the command line.

The following list explains some of the gacutil options:

  • gacutil /l lists all assemblies from the assembly cache.

  • gacutil /i mydll installs the shared assembly mydll into the assembly cache.

  • gacutil /u mydll uninstalls the assembly mydll.




Professional C# 2005 with .NET 3.0
Professional C# 2005 with .NET 3.0
ISBN: 470124725
EAN: N/A
Year: 2007
Pages: 427

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net