.NET
GAC
Assembly
Local Copy
.NET Development

How can I force .NET to use a local copy of an assembly that's in the GAC

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

In .NET, the Global Assembly Cache (GAC) is a machine-wide code cache for the Common Language Infrastructure (CLI). Assemblies deployed in the GAC can be shared among multiple applications on the system. However, there are situations where you might want to force a .NET application to use a local copy of an assembly instead of the one in the GAC. This can arise when dealing with different assembly versions or debugging specific behaviors.

Table of Contents

Reasons for Using a Local Assembly Copy

There are several scenarios where using a local assembly copy is preferable:

  • Development and Debugging: When you're developing and need to test different versions of an assembly.
  • Rolling Back Changes: After replacing a GAC assembly with a newer version and needing a quick rollback.
  • Version Specific Testing: When you need to test different versions without modifying the GAC.
  • Avoiding Conflicts: To ensure no conflicts arise with shared assemblies used by other applications.

The Order of Assembly Resolution

Before delving into the methods, let's understand how .NET resolves assembly locations:

  1. Application Base Directory: Checks if the assembly exists in the application directory.
  2. Private Path: Looks into directories specified in the `probing` element of the application configuration.
  3. GAC: Searches for the assembly in the GAC.
  4. CodeBase: Utilizes the `codeBase` element in the configuration file for specific version requests.

Ways to Override the GAC

Application Configuration File

The primary way to override assembly resolution is through the application's configuration file. This involves modifying the `app.config` or `web.config` file to specify where .NET should look for assemblies.

CodeBase Element

The `codeBase` element explicitly points to the location of an assembly file. It can be used for strong-named assemblies to redirect where .NET should resolve the assembly to.


Course illustration
Course illustration

All Rights Reserved.