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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

Suggested Solutions

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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.…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit If you want to manage em…

730 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