views:

356

answers:

3

Can I configure a .NET application in a way (settings in Visual Studio) that it references a "local" assembly (not in GAC) instead of an assembly within the GAC, although both assemblies have the same name and the same version?

+1  A: 

Did you see this answer?
http://stackoverflow.com/questions/991293/forcing-the-asp-net-application-to-load-the-assembly-from-bin-not-from-gac/991502#991502

It sounds like you are trying to do the same thing.

Theresa
Oh I didn't find this answer when I searched StackOverFlow for this topic. But you're right, finally the question is almost the same.
Flo
+3  A: 

If both assemblies are strong-named (signed), the CLR will always load from the GAC.

Here are the steps the runtime uses to resolve assembly references (from How the Runtime Locates Assemblies):

  1. Determines the correct assembly version by examining applicable configuration files, including the application configuration file, publisher policy file, and machine configuration file. If the configuration file is located on a remote machine, the runtime must locate and download the application configuration file first.

  2. Checks whether the assembly name has been bound to before and, if so, uses the previously loaded assembly. If a previous request to load the assembly failed, the request fails immediately without attempting to load the assembly.

  3. Checks the global assembly cache. If the assembly is found there, the runtime uses this assembly.

  4. Probes for the assembly (... some material omitted ...)

As stated later in that same article:

There is no version checking for assemblies without strong names, nor does the runtime check in the global assembly cache for assemblies without strong names.

So if you can afford to remove signing from the local assembly, the application will use it instead of the one in the GAC.

For more detail than you could probably ever want about the runtime-binding mechanisms, see Suzanne Cook's blog.

This blog entry from Scott Hanselman also provides a great overview of the binding process.

Jeff Sternal
A: 

Hello Flo,

To successfully deploy your .NET Framework application, you must understand how the common language runtime locates and binds to the assemblies that make up your application. By default, the runtime attempts to bind with the exact version of an assembly that the application was built with. This default behavior can be overridden by configuration file settings.

You can view binding information in the log file using the Assembly Binding Log Viewer (Fuslogvw.exe), which is included in the Windows Software Development Kit (SDK).

Muse VSExtensions