Understanding the Global Assembly Cache (GAC) and Managing, Copying DLLs from Global Assembly Cache
Most of you may be confused why there are two GACs available in the machine:
- C:\WINDOWS\assembly
- C:\WINDOWS\Microsoft.NET\assembly
What is the GAC?
GAC is a shared location in your machine that keeps assemblies, DLLs for common sharing purposes. Assume that you are using system.data.dll in your project. One option is you can place the DLL in your project but assume you are creating another project which is also using the same .NET assembly system.data.dll. It is better to have it in a common place that can be referred to.
Since it is a common frameworkDLLl and used separately from your application logic, it is good to place it in a shared place for ease of maintenance and update process.
What is C:\WINDOWS\assembly? http://lh6.ggpht.com/-GVy_-ZrP5A8/VMB4zMCFBKI/AAAAAAAADqQ/-Hqs1kiKJR0/image_thumb5.png?imgmax=800
Previous CLRs used this place as it's a common location for DLLs. Previous CLRs includes versions 1.0, 1.1, 2.0. These CLR versions were used before .NET Framework 4.0.
.NET Framework 1.0 - CLR v1.0
.NET Framework 1.1 - CLR v1.1
.NET Framework 2.0 - CLR v2.0
.NET Framework 3.0 - CLR v2.0
.NET Framework 3.5 - CLR v2.0
If you are working with applications belongings to these versions then this is the place for your Global Assembly Cache.
What is C:\WINDOWS\Microsoft.NET\assembly?
After CLR version 4.0, Microsoft changed their location to this one for maintaining and to avoid loading the wrong DLL in applications for backwards compatibility.
.NET Framework 4.0 - CLR v4.0
.NET Framework 4.5 - CLR v4.0
.NET Framework 4.5.1 CLR v4.0
.NET Framework 4.5.2 CLR v4.0
If you are engaging with an application after the .NET Framework 4.0, this is the default location for its assemblies.
Managing and Copying DLLs from Global Assembly Cache
- shfusion.dll
- Gacutil.exe
shfusion.dll
This is a windows shell extension which shifts before Framework 4.0 to manage DLLs in the GAC.
If you navigate to C:\WINDOWS\assembly from your file explorer you can see something like this that you can not manipulate:
http://lh6.ggpht.com/-KSaRwDjf9Q4/VMB40oInlkI/AAAAAAAADqg/bkXaOW-SU6U/image_thumb4.png?imgmax=800
You can use the following command to manipulate it:
- Go to command prompt (cmd) and open it under Run as Administrator
- Run the command:
C:\Windows\system32>regsvr32 /u C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\shfusion.dll
http://lh3.ggpht.com/-As0tMvsWiZg/VMB5jOr2sQI/AAAAAAAADqw/S1E-YZ15jzE/image_thumb2.png?imgmax=800
When you click Enter it will prompt with a message as below which will turn your GAC into a manageable state.
http://lh5.ggpht.com/-3GvCk78WE08/VMB6R4NpbaI/AAAAAAAADrA/7Ffc0CC5Fvs/image_thumb6.png?imgmax=800
If you navigate to C:\WINDOWS\assembly you can see it by yourself.
http://lh6.ggpht.com/-ZQsVF6mROXk/VMB6TQRAoyI/AAAAAAAADrQ/bamG45v_K7Y/image_thumb9.png?imgmax=800
You can revert it back to normal by registering the DLL again:
C:\Windows\system32>regsvr32 C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\shfusion.dll
shfusion.dll is only available for Framework 4.0 and its versions. It is discontinued and not shipping with future frameworks. If you are having multiple versions installed use the latest framework folder.
EX:- Microsoft.NET\Framework\.NET version> \shfusion.dll
Gacutil.exe
This the alternative if you are dealing with DLLs after Framework 4.0. You need to use the gacutil.exe. You can type gacutil into the Visual Studio command prompt to get a list of commands available for DLL manipulation.
http://lh5.ggpht.com/-QDPsEH1R0iE/VMB6UoDiJyI/AAAAAAAADrg/IlQug2YxThg/image_thumb%25255B1%25255D.png?imgmax=800