Global Assembly Cache: How to Clean and Manage GAC
In this article
Cleaning the Global Assembly Cache (GAC) involves removing outdated, redundant, or incorrect versions of shared .NET assemblies to resolve version conflicts and ensure that applications load the intended DLLs. The GAC is a machine-wide folder used by the .NET Framework to store assemblies that are shared across multiple applications, preventing the need to duplicate the same library in every application folder. Cleaning it is typically necessary when a manual installation of a library has failed or when a "strong-named" assembly version mismatch is preventing a program from launching.
What You'll Need
- A computer running Windows with the .NET Framework installed.
- Administrative privileges (Administrator account) to modify system folders.
- The Global Assembly Cache Assembly Tool (GacUtil.exe), which is included with the Windows SDK or Visual Studio.
- The exact name and version of the assembly you intend to remove.
Step-by-Step
- Identify the Assembly to Remove: Before attempting to clean the GAC, you must know the exact identity of the assembly. Navigate to the GAC directory to verify the presence of the DLL. For .NET Framework 4.0 and later, the GAC is located at
C:\Windows\Microsoft.NET\assembly. Note that this is a complex folder structure; you may need to search for the specific DLL name within this directory. - Open the Developer Command Prompt: You cannot use a standard Command Prompt for GAC operations because the
gacutil.exetool is not in the default system path. Search for "Developer Command Prompt for VS" in your Start menu. Right-click the application and select "Run as Administrator." This is critical, as the GAC is a protected system area. - Verify the Assembly Version: To ensure you are removing the correct version, use the
sn.exe(Strong Name tool) if you have the file locally, or check the folder name in the GAC directory. The GAC organizes files by version and public key token; removing the wrong version can break other installed software. - Execute the Uninstall Command: Use the
gacutilcommand with the/u(uninstall) switch. Type the following command and press Enter:gacutil /u AssemblyName
If you need to remove a specific version of an assembly while keeping others, use the full assembly identity:gacutil /u AssemblyName, Version=x.x.x.x, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxx - Confirm Removal: After the command executes, the console should report that the assembly was uninstalled successfully. To verify, navigate back to the
C:\Windows\Microsoft.NET\assemblyfolder and confirm that the specific version folder for that assembly has been deleted. - Restart Dependent Applications: If you cleaned the GAC to resolve a versioning conflict for a specific piece of software, restart that application. The .NET runtime will now be forced to look for the assembly in the application's local directory (bin folder) rather than the GAC.
Common Mistakes
- Manually Deleting Folders: Attempting to delete DLLs directly from the
C:\Windows\Microsoft.NET\assemblyfolder using File Explorer is highly discouraged. The GAC uses a complex mapping system; manual deletion can leave orphaned entries in the registry or metadata that confuse the .NET loader. - Running without Admin Rights: Running the Developer Command Prompt as a standard user will result in an "Access Denied" error, as the GAC is a system-protected directory.
- Removing System Assemblies: Accidentally uninstalling assemblies that start with "System." or "Microsoft." can lead to catastrophic OS instability or the failure of critical Windows services. Only remove third-party assemblies that you have explicitly installed.
- Ignoring the Public Key Token: In environments with multiple versions of the same assembly, failing to specify the version and public key token may result in the tool removing the wrong version or failing to find the target.
Tips
- Use Local Deployment: To avoid GAC issues entirely, prefer "private assembly" deployment. By placing your DLLs in the same folder as your executable, the .NET runtime checks the local folder before checking the GAC, making updates easier to manage.
- Backup Before Cleaning: If you are unsure about an assembly, copy the folder from the GAC to a backup location on your desktop before running
gacutil /u. This allows for a quick manual restoration if a critical dependency is lost. - Check the Fusion Log: If you are cleaning the GAC because of "File Not Found" or "Version Mismatch" errors, use the Assembly Binding Log Viewer (Fuslogvw.exe). This tool tells you exactly which version of an assembly the application is looking for and where it is searching.
Troubleshooting
If gacutil /u returns an error stating that the assembly could not be found, double-check the spelling of the assembly name. Ensure you are not including the .dll extension in the command; use the assembly name only (e.g., use MyLibrary instead of MyLibrary.dll).
If you receive a "Permission Denied" error despite being an administrator, check if a process is currently using the assembly. Use a tool like Process Explorer to see if any running application has a handle on the DLL in question. Close the application and try the command again.
If the assembly persists after uninstallation, check for multiple GAC locations. Older versions of .NET (1.x through 3.5) use C:\Windows\assembly, while .NET 4.0+ uses C:\Windows\Microsoft.NET\assembly. Ensure you are targeting the correct framework version.
Frequently Asked Questions
Does cleaning the GAC slow down my computer?
No. Cleaning the GAC does not impact system performance. In fact, it can resolve application crashes caused by version conflicts, leading to a more stable environment.
Can I clean the GAC using a third-party cleaner tool?
It is not recommended. Most general system cleaners do not understand the .NET assembly mapping. Using gacutil.exe is the only supported and safe method for removing assemblies.
What happens if I remove a required assembly?
The application that depends on that assembly will throw a System.IO.FileNotFoundException or a System.BadImageFormatException the next time it attempts to load that specific library.
Is the GAC used in .NET Core or .NET 5/6/7/8?
No. The Global Assembly Cache is a feature of the .NET Framework. .NET Core and subsequent versions (.NET 5+) use a different deployment model that emphasizes local, side-by-side installations to avoid the "DLL Hell" associated with the GAC.
Do I need to restart my PC after cleaning the GAC?
Generally, no. You only need to restart the specific applications that were using the assembly so they can reload the correct version from the disk.