Channels ▼


.NET and DLL Hell

“DLL Hell” was a phrase coined many years ago to describe a problem that is inherent in Windows’ method of sharing code: the Dynamic Link Library. In this and the next newsletter, I will outline what causes DLL Hell and how .NET solves these specific issues. I will start by describing the underlying causes of DLL Hell and explain .NET’s solution in the next newsletter.

The "D" in DLL refers to the the fact that the linking of libraries to a process occurs dynamically at run time rather than statically by the compiler. It's true that a developer can statically link to an import library, but the DLL is still linked at run time. The reason is because the import library gives the compiler enough information to build an Import Address Table, which contains information about the DLL and the function to be imported. The compiler directly calls to the DLL functions to entries in the IAT. At run time, the LoadLibraryEx Win32 function is called to load the DLL and the IAT entries are overwritten with the actual address of the functions in the DLL. The developer can also call LoadLibraryEx to explicitly load the DLL and then call GetProcAddress to get the address of the function; this involves messing around with function pointers, but it does give the developer a better opportunity to handle the situation when a DLL is missing or does not have the requested function.

Notice that both of these mechanisms use LoadLibraryEx. DLL Hell occurs mainly because LoadLibraryEx is passed the name of the DLL to load. This can be an absolute path, indicating a DLL in a specific folder, but typically it is just the name of the DLL. If the path is omitted, then LoadLibraryEx will use an algorithm to locate the DLL (take a look in the entry for this function in the MSDN library for complete details), which includes the Windows system folder (for shared DLLs) and the folders in the PATH environment variable. The problem is that LoadLibraryEx loads a DLL by name and although PE (portable executable) files can have a version resource, this is not part of the name. Two versions of the same DLL must have different names, otherwise LoadLibraryEx could load the wrong version of a DLL, or it could even load a totally different DLL that has the same name.

COM helps because the actual location of a library is stored in the registry and the client code never uses DLL names and paths, but instead refers to class names (CLSIDs), and the COM system resolves the class name to a DLL path through a registry lookup. The strict rules of COM are such that if a class changes, then its CLSID should also change, and so the DLL housing the class should change as well. However, people broke these rules, so DLL Hell persisted into COM code (if developers had followed the COM rules, then DLL Hell would have gone away). COM's reliance on the registry was also a problem because it meant that the library would have to be installed before use, and uninstalled when the application was removed.

So, the problems of using Win32 DLLs come down to these issues:

  1. LoadLibraryEx loads DLLs by name and pays no regard to the version of the file requested.
  2. PE file names do not have an explicit version component and so different versions of the same DLL coexist badly: A later installed version will overwrite an earlier installed version in the same folder.
  3. LoadLibraryEx has a search algorithm to locate DLLs and, although you can tweak this algorithm, it's largely an all or nothing affair: You either use it or you don't. If the algorithm does not work for you, then you have to give an absolute path. If the algorithm fails, there is no information about where the algorithm has searched to allow you to rectify the problem.
  4. If you want to share a library between applications, you have to place it in a folder that all applications have access to (typically the Windows system folder is used) and this means that only one version of this library can exist.

There were ways to get round these problems, but basically they were just small fixes to a flawed process. To get round all of these problems, the .NET team came up with an entirely different mechanism called Fusion, which I will describe in the next newsletter.

As a postscript, the DotNet Developer Group in the UK ( has recently had its inaugural meeting at Microsoft's Thames Valley Park campus. I spoke at that meeting, and I'll speak at some of their other meetings later this year. If you're in the UK, come along to one of these user meetings and listen to some great talks about .NET

Richard Grimes speaks at conferences and writes extensively on .NET, COM, and COM+. He is the author of Developing Applications with Visual Studio .NET (Addison-Wesley, 2002). If you have comments about this topic, Richard can be reached at [email protected].

Related Reading

More Insights

Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.