Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


How CLR Searches for dlls

Posted on 2014-02-16
Medium Priority
Last Modified: 2014-02-21
Could someone tell if this article http://www.thescarms.com/dotNet/assembly.aspx 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  ----      http://www.thescarms.com/dotNet/assembly.aspx
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 1500 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 http://msdn.microsoft.com/en-us/library/yx7xezcf(v=vs.85).aspx.

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 http://msdn.microsoft.com/en-us/library/yx7xezcf(v=vs.85).aspx.

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

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…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
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. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?

580 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