Solved

How CLR Searches for dlls

Posted on 2014-02-16
1
368 Views
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
Section:
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
0
Comment
Question by:metro156
1 Comment
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 500 total points
Comment Utility
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.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

762 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

6 Experts available now in Live!

Get 1:1 Help Now