In what order are locations searched to load referenced DLLs?

.NetDll

.Net Problem Overview


I know that the .NET framework looks for referenced DLLs in several locations

  • Global assembly cache (GAC)
  • Any private paths added to the AppDomain
  • The current directory of the executing assembly

What order are those locations searched? Is the search for a DLL ceased if a match is found or does it continue through all locations (and if so, how are conflicts resolved)?

Also, please confirm or deny those locations and provide any other locations I have failed to mention.

.Net Solutions


Solution 1 - .Net

Assembly loading is a rather elaborate process which depends on lots of different factors like configuration files, publisher policies, appdomain settings, CLR hosts, partial or full assembly names, etc.

The simple version is that the GAC is first, then the private paths. %PATH% is never used.

It is best to use Assembly Binding Log Viewer (Fuslogvw.exe) to debug any assembly loading problems.

EDIT http://msdn.microsoft.com/en-us/library/aa720133.aspx explains the process in more detail.

Solution 2 - .Net

I found an article referencing the MSDN article on DLL search order that says

> For managed code dependencies, the > Global Assembly Cache always prevails; > the local assembly in application > directory will not be picked up if > there is an existing (or newer with > policy) copy in the GAC.

Considering this, I guess the MSDN list is correct with one addition

0. Global assembly cache

Solution 3 - .Net

"No longer is the current directory searched first when loading DLLs! This change was also made in Windows XP SP1. The default behavior now is to look in all the system locations first, then the current directory, and finally any user-defined paths."

(ref. http://weblogs.asp.net/pwilson/archive/2003/06/24/9214.aspx">http://weblogs.asp.net/pwilson/archive/2003/06/24/9214.aspx</a>;)

The default serach order, which can be changed by the application, is also described on MSDN: http://msdn.microsoft.com/en-us/library/ms682586.aspx">http://msdn.microsoft.com/en-us/library/ms682586.aspx</a>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAnthony MastreanView Question on Stackoverflow
Solution 1 - .NetLars TruijensView Answer on Stackoverflow
Solution 2 - .NetAnthony MastreanView Answer on Stackoverflow
Solution 3 - .NetAnders SandvigView Answer on Stackoverflow