Assemblies
An assembly is the actual .dll
file on our hard drive where the classes in the .NET Framework are stored. For
example, all the classes contained in the ASP.NET Framework are located in an
assembly named System.Web.dll. In other word, an assembly is the primary unit of
deployment, security, and version control in the .NET Framework. The .NET
Framework (version 2.0) includes 51 assemblies.
There are two types of
assemblies:
- Private: A private assembly can be used by only a single application.
- Shared: A shared assembly can be used by all applications located on the same server.
Shared assemblies are
located in the Global Assembly Cache (GAC). For example, the System.Web.dll
assembly and all the other assemblies included with the .NET Framework are
located in the Global Assembly Cache. GAC is physically located in our
computer's \WINDOWS\Assembly folder. There is a separate copy of every assembly
in your \WINDOWS\Microsoft.NET\Framework\v2.0.50727 folder. The first set of
assemblies is used at runtime and the second set is used at compile time.
Before we can use a class
contained in an assembly in our application, we must add a reference to the
assembly. By default, an ASP.NET application references the most common
assemblies contained in the Global Assembly Cache:
- mscorlib.dll
- System.dll
- System.Configuration.dll
- System.Web.dll
- System.Data.dll
- System.Web.Services.dll
- System.Xml.dll
- System.Drawing.dll
- System.EnterpriseServices.dll
- System.Web.Mobile.dll
To use any particular class
in the .NET Framework, we must do two things. First, our application must
reference the assembly that contains the class. Second, our application must
import the namespace associated with the class. In most cases, we won't worry
about referencing the necessary assembly because the most common assemblies are
referenced automatically or say by default. However, if we need to use a
specialized assembly, we need to add a reference explicitly to the assembly. For
example, if we need to interact with Active Directory by using the classes in
the System.DirectoryServices namespace then we will need to add a reference to
the System.DirectoryServices.dll assembly to our application.
Each class entry in the
.NET Framework SDK documentation lists the assembly and namespace associated
with the class. For example, if we look up the MessageQueue class in the
documentation, we will discover that this class is located in the
System.Messaging namespace located in the System.Messaging.dll assembly.
If we are using Visual Web
Developer, we can add a reference to an assembly explicitly by selecting the
menu option Website, Add Reference, and selecting the name of the assembly that
we need to reference.
For example, to add a
reference to the System.Messaging.dll assembly results in the web configuration
file as given below.
<?xml
version="1.0"?>
<configuration>
<system.web>
<compilation>
<assemblies>
<add
assembly="System.Messaging,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
</assemblies>
</compilation>
</system.web>
</configuration>
If we prefer not to use
Visual Web Developer, then we can add the reference to the
System.Messaging.dll
assembly by creating the above file by other hand.
HAVE A GREAT
CODING!