Introduction to ASP.NET - Assemblies
(Page 5 of 10 )
Also known as Managed DLLs, assemblies are the fundamental unit of deployment for the .NET platform. The .NET Framework itself is made up of a number of assemblies, including mscorlib.dll, among others. The assembly boundary is also where versioning and security are applied.
An assembly contains Intermediate Language generated by a specific language compiler, an assembly manifest (containing information about the assembly), type metadata, and resources. We’ll discuss IL, manifests, and metadata later in this section.
Assemblies can be either private, residing in the directory of the client application from which they are used (or, in the case of ASP.NET, in the / bin subdirectory of the Web application), or shared. Shared assemblies are stored in a common location called the Global Assembly Cache (GAC). Assemblies that are to be installed in the GAC must be strongly named, which means that they must have a cryptographic key associated with them. Strong naming can be accomplished either through Visual Studio .NET, or you can use the sn.exe tool supplied with the .NET Framework SDK to generate a key pair for signing the assembly, and then use the al.exe tool to create the signed assembly based on the generated key. We’ll demonstrate creating and sharing strongly named assemblies in Chapter 6.
Assemblies are self-describing, thanks to the manifest contained within them. One advantage of their self-describing nature is that it makes it possible for different versions of the same assembly to be run side by side. Clients can then specify the version of the assembly that they require, and the CLR will make sure that the correct version of the assembly is loaded for that client at runtime.
Intermediate Language (IL) IL, also known as MSIL (for Microsoft Intermediate Language), is a processor-independent representation of executable code. IL is similar in some ways to assembly code, but it is not specific to a particular CPU; rather, it is specific to the CLR. IL is generated by each of the language compilers that target the CLR. As mentioned above, .NET assemblies contain IL that is to be executed by the CLR.
At runtime, the CLR just-in-time (JIT) compiles the IL to native code, which is then executed. There is also a tool called ngen.exe, which is supplied with the .NET Framework SDK and allows you to precompile assemblies to native code at install time and cache the precompiled code to disk. However, while precompiling an assembly to native code will improve the startup time of an assembly, the JIT process used by the CLR performs optimizations that may allow JITed code to perform better than precompiled code, the difference in performance will depend on the code being executed, and how subject to these optimizations it is.
Managed Execution Managed execution refers to code whose execution is managed by the CLR. This execution includes memory management, access security, cross-language integration for debugging and/or exception handling, and many other features. Managed assemblies are required to supply metadata that describes the types and members of the code contained within the assembly. This information allows the CLR to manage the execution of the code.
Note that not all languages in Visual Studio .NET are managed. While Visual C++ offers what are called the “Managed Extensions for Visual C++,” it is still possible to write unmanaged code in Visual C++.
Manifests, Metadata, and Attributes Metadata and manifests are key pieces of the managed execution world. Manifests are the portion of an assembly that contains descriptive information about the types contained in the assembly, the members exposed by the assembly, and the resources required by the assembly. The manifest contains metadata, which, simply put, is data that describes the assembly. Some metadata is generated by the language compiler at compile time. The developer may add other metadata at design time through the use of attributes. Attributes are declarations added to code that describe some aspect of the code or modify the code’s behavior at runtime.
Attributes are stored with an assembly as metadata and are used for many purposes in the .NET Framework—from the attribute used to turn a normal method into a web service to attributes used to define how custom controls interact with the Visual Studio .NET environment.
 | If you've enjoyed what you've seen here, or to get more information, click on the "Buy the book!" graphic. Pick up a copy today!
Visit the O'Reilly Network http://www.oreillynet.com for more online content. |
Next: Object Orientation in the .NET Platform >>
More ASP.NET Articles
More By O'Reilly Media