How CLR Searches for dlls

Posted on 2014-02-16
Last Modified: 2014-02-21
Could someone tell if this article is correct on how CLR searches for it's dlls?

If James Burger is reading this, please tell me in reference to question entitled : Reference DLLs in your .NET Application you answered differently. James you indicated the GAC was searched last.

See  Article  ----
Quick Fix Engineering
If a referenced assembly has a strong name the load process is as follows:

• Assembly configuration files (discussed later) are examined to see what version of a referenced assembly to load.

• The CLR checks if the assembly was loaded in a previous call. If so, it is used.

• If the assembly isn't loaded the GAC is queried for a match and if found that's what's loaded.

• If a configuration file has a codebase entry for the assembly the file specified by this entry is used.

• If none of the above exist, the CLR looks for the referenced assembly starting in the application folder.

• If still not found, the CLR asks the Windows Installer service if it has the assembly. If so, the assembly is installed and this is the assembly used. This is call install on demand.

• If the assembly still cannot be found, an error is raised
Question by:metro156
1 Comment
LVL 40

Accepted Solution

Jacques Bourgeois (James Burger) earned 500 total points
ID: 39863828
I am there.

The problem with what you are asking is that it cannot be represented only with a series of steps. A flowchart would be needed because there are a few ifs in there.

No matter where you look for, the first item is always something like "configuration files are examined to see what version of a referenced assembly to load." This skew everything else in the search. If there is nothing in the assembly configuration file, its straight to the GAC. But if there is something in the configuration files that points to another version than the one was compiled into the manifest or that requests remoting (meaning that the dll needs to be loaded or to run from the network).

The search will also be different whether the assembly is signed or not, because an assembly that is not signed cannot be stored in the GAC or be used through remoting.

Not always 1. 2. 3. 4.

Read 3 different articles on the topic, and they will all have variations on the sequence.

Your best bet would thus to go to the official documentation at

Yes, it comes in contradiction with what I told in my old post. It looks in the GAC first.
So who's wrong? James Burger or Microsoft. Probably not James Burger. And if you want the best answer, I would bet on Microsoft, not on me.

But I assume my contradiction.

In my work, I have to deal with the real world of a programmer. By experience, I know that this question is not so important. What is important is not where the framework looks, but that it finds the right assembly. And this is controlled more by the configuration files more than anything.

The only times I had problems with locating assemblies (and it happened more than once), where when I ended up with the wrong version of a dll, or more precisely, with the "right" version not installed. And this is controlled in step 1, in the configuration files.

When you have a problem such as that one, it is usually because the required version of a dll is not installed in the GAC, so knowing if the GAC is searched first or last has no impact, unless a programmer is stupid enough to distribute 2 different versions of a dll with the same signature and version number. I have to admit that there are quite a few stupid programmers that do that, but I never use dlls written by such programmers, so I don't care.

Knowing what the configuration files and a CodeBase can do is more important than knowing if the GAC is search first or last. I have always works with that assumption, and it has served me well for more than a decade.

If you really want to stick to the real thing, not the practical one, then nothing is as good as

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now