Assemblies are the building blocks of .NET Framework applications; they form the fundamental unit of deployment, version control, reuse, activation scoping, and security permissions. An assembly is a collection of types and resources that are built to work together and form a logical unit of functionality. An assembly provides the common language runtime with the information it needs to be aware of type implementations. To the runtime, a type does not exist outside the context of an assembly. Assemblies are a fundamental part of programming with the .NET Framework. An assembly performs the following functions: Assemblies can be static or dynamic: Static assemblies can include .NET Framework types (interfaces and classes), as well as resources for the assembly (bitmaps, JPEG files, resource files, and so on). Static assemblies are stored on disk in PE files. You can also use the .NET Framework to create dynamic assemblies, which are run directly from memory and are not saved to disk before execution. You can save dynamic assemblies to disk after they have executed.There are several ways to create assemblies. You can use development tools, such as Visual Studio .NET, that you have used in the past to create .dll or .exe files. You can use tools provided in the .NET Framework SDK to create assemblies with modules created in other development environments. You can also use common language runtime APIs, such as Reflection.Emit, to create dynamic assemblies. | |
In general, a static assembly can consist of four elements: | |
Assembly Manifestdescribes the assembly with all the information that is needed to reference it and lists all its dependencies. The parts of the assembly manifest are as follows: Identity - (name, version,culture, and public key) A list of files -Files belongs to this assembly. A single assembly must have at least one file but may contain a number of files. A list of referenced assemblies -All assemblies used from the assembly are documented inside the manifest. This reference information inludes version number and public key, which is used to uniquely identify assemblies. A set permission requests -These are the permissions needed to run this assembly. Exported types -These are included if they are defined within a module and the module is referenced from the assembly. otherwise, they are not part of the manifest. A module is a unit of reuse. The type description is stored as metadata inside the assembly. | |
assembly manifest - An integral part of every assembly that renders the assembly self-describing. The assembly manifest contains the assembly's metadata. The manifest establishes the assembly identity, specifies the files that make up the assembly implementation, specifies the types and resources that make up the assembly, itemizes the compile-time dependencies on other assemblies, and specifies the set of permissions required for the assembly to run properly. This information is used at run time to resolve references, enforce version binding policy, and validate the integrity of loaded assemblies. The self-describing nature of assemblies also helps makes zero-impact install and XCOPY deployment feasible. metadata - Information that describes every element managed by the common language runtime: an assembly, loadable file, type, method, and so on. This can include information required for debugging and garbage collection, as well as security attributes, marshaling data, extended class and member definitions, version binding, and other information required by the runtime. | |
Using Reflection. | |
Version information is stored in assembly in manifest. | |
Versioning concept is only applicable to global assembly cache (GAC) as private assembly lie inthere individual folders. | |
NameSpace Logically group types. Ex: System.Web.UI logically groupsour UI related features. | |
There are two ways to install .NET assembly in GAC:- | |
During development process you will need strong name keys to be exposed to developer whichwill is not a good practice from security aspect point of view.In such situations you can assign thekey later on and during development you an use delay signing Following is process to delay sign a assembly: For Example: [assembly:AssemblyKeyFileAttribute("myKey.snk")] [assembly:AssemblyDelaySignAttribute(true)] The compiler inserts the public key into the assembly manifest and reserves space in the PE file forthe full strong name signature. The real public key must be stored while the assembly is built sothat other assemblies that reference this assembly can obtain the key to store in their own assemblyreference. Sn –Vr myAssembly.dll Just before shipping, you submit the assembly to your organization's signing authorityfor the actual strong name signing using the –R option with the Strong Name tool.Thefollowing example signs an assembly called myAssembly.dll with a strong name usingthe sgKey.snk key pair Sn -R myAssembly.dll sgKey.snk | |
Garbage collection is a CLR feature which automatically manages memory.CLR automatically releases objects when they are no longerreferenced and in use.CLR runs on non-deterministic to see the unused objects and cleans them.One side effect of this non-deterministic feature is that we cannot assume an object is destroyedwhen it goes out of the scope of a function. Therefore, we should not put code into a classdestructor to release resources. | |
System.GC.Collect() forces garbage collector to run.This is not recommended but can be used ifsituations arises. | |
All .NET assemblies have metadata information stored about the types defined in modules.Thismetadata information can be accessed by mechanism called as “Reflection”.System.Reflection canbe used to browse through the metadata information. Using reflection you can also dynamically invoke methods using System.Type. | |
JIT compiler is a part of the runtime execution environment. In Microsoft .NET there are three types of JIT compilers: | |
Dotnet Framework Interview Questions
Posted by
Ramu