Question

Keeping things simple, assume are no DLLs in the local folder, or configuration files involved, or publisher policies, or custom resolution. The only place referenced DLLs are is in the GAC.

How does fusion decide which version of the DLLs in the GAC to go for (all other things equal), what is the order of priority?

For example if in my project, I have referenced a DLL of version 10.5.0.0. Would it pick the DLL of version 10.5.0.0 or 10.5.1.0. Alternatively if I only had version 10.4.0.0 in the GAC, would it work or throw an error? Do these rules change depending on if it's the major/minor/build/revision part that changes?

How does this differ if the project reference "Specific Version" is set to True or False?

And how does this differ if the reference is a DLL reference or project reference?

I'm guessing there's a MSDN website somewhere stating how this works, but I can't seem to find it. I am not looking to override the behaviour, I just want to know what the default behaviour is.

Was it helpful?

Solution

It is documented on MSDN in How the Runtime Locates Assemblies. In particular the GAC is only searched if the assembly is loaded using a strong name. There may still be publisher policies in place that "redirects" to another assembly but there are no automatic rules in place.

In my opinion the GAC is only something that should be used by Microsoft for the .NET Framework and you can remove a lot of pain by distributing your application or library without using the GAC (except for the .NET Framework of course).

Referencing a specific version of an assembly is a build time property and it does not affect the run time behavior. However, when an assembly reference is compiled into an executable the version is stored in the executable and at run time that specific version is loaded (after assembly redirect rules have been applied).

So to sum it up: In order for .NET to load another version of the assembly requested there has to be an assembly redirect in place. Your application can provide redirects in the app.config file and the GAC can have publisher policies.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top