In .NET, is there a need to register the DLL?

Helios picture Helios · Dec 26, 2008 · Viewed 23.5k times · Source

Is it necessary to register a compiled DLL (written in C# .NET) on a target machine.

The target machine will have .NET installed, is it enough to simply drop the DLL onto the target machine?

Answer

Jorge Córdoba picture Jorge Córdoba · Dec 27, 2008

I think you're confusing things a little. Registering a dll has never been needed in order to use it.

Using a dll requires only to load it (given a known location or if the library is in the system path) and get the address of the function you wanted to use.

Registering the dll was used when distributing COM or ActiveX objects which need to add certain entries to the windows registry. In order to use a COM service (for example) you need to reference a GUID — that is, a unique identifier — which allows you to get a handle to the dll that implements the service (or provide access to it). Sometimes you can make reference to a fully-qualified name and get the same results.

In order for all that to work the dll needed to be registered. This "registration" process just creates several entries in the registry, but mainly these two: one associating a GUID with the location of the dll (so that you can reference it through the GUID without knowing where is it exactly located) and a second one associating the full name with the GUID. But again, this is just for COM or ActiveX objects.

When you develop an application in .NET, the libraries referenced on your project are automatically loaded when they're needed without you having to worry about locating or loading them. In order to to that, the framework checks two locations for the referenced libraries.

  • The first location is the application path.
  • The second location is the GAC.

The GAC (Global Assembly Cache) allows you to effectively register a dll to be used throughout the system and works as an evolution of the old registering mechanism.

So basically you just need to put the dll in the same folder of the application.