.NET Frameworks Questions
https://www.indiabix.com/technical/dotnet/dot-net-framework/
https://www.dotnetcurry.com/ShowArticle.aspx?ID=64
What is IDisposable?
[sc name=”reportlinkbutton”]
https://stackoverflow.com/questions/538060/proper-use-of-the-idisposable-interface
The .NET Framework -Assembly
When a program uses a DLL, a dependency is created. If another program overwrites and breaks this dependency, the original program may not successfully run. With the introduction of the Microsoft .NET Framework, most dependency problems have been eliminated by using Assemblies.
An assembly is a logical unit of functionality that runs under the control of the .NET common language runtime (CLR). A dll is an assembly, but an assembly can be DLL or Exe. Dlls and exes are self-deployable units. However, internally an assembly is very different from a Microsoft Win32 DLL. Assemblies are very similar to Java Archives (JAR).
What are the contents of assembly?
A static assembly can consist of four elements:
Assembly manifest – The assembly manifest contains the assembly metadata that provides all the information that is required for an assembly to be self-describing. Like Assembly name, Version information, The assembly list of files etc. Type metadata – Binary information that describes a program. Microsoft intermediate language (MSIL) code. A set of resources.
What are the different types of assembly?
Assemblies can also be private or shared/Global. A private assembly is installed in the installation directory of an application and is accessible to that application only. On the other hand, a shared assembly is shared by multiple applications. A shared assembly has a strong name and is installed in the GAC (Global Assembly Cache).
What is a strong name?
You need to assign a strong name to an assembly to place it in the GAC and make it globally accessible. A strong name consists of a name that consists of an assembly’s identity (text name, version number, and culture information), a public key and a digital signature generated over the assembly. The .NET Framework provides a tool called the Strong Name Tool (Sn.exe), which allows verification and key pair and signature generation.
Common Language Runtime (CLR)
The .NET Framework provides a run-time environment called the common language runtime, which runs the code and provides services that make the development process easier. All programs written for the .NET framework, regardless of programming language, are executed by the CLR. It provides exception handling, Garbage collection and thread management. In a process known as just-in-time (JIT) compilation, the CLR compiles the intermediate language code known as Common Intermediate Language (CIL) into the machine instructions that in turn are executed by the computer’s CPU.
When we compile our code written in any .net language the associated compiler (like C#,VB Compiler) generates binaries called assembly which contains IL code .These Instructions are low level human readable language which can be converted into machine language by the run time compiler during its first execution.It is done just during execution so that the compiler will have before hand knowledge of which environment it’s going to run so that it can emit the optimized machine language code targeting that platform. The .net Framework’s such compiler is called Just-in-Time (JIT) compiler or Jitter.
A .net assembly consist of following elements:
1. A Win32 file Header – The header data identifies the kind of application (console,Windows,code lib ) to be hosted by Windows operating system.
2. A CLR file Header- The CLR header is a block of data that provides information which allow it to be hosted by the CLR. CLR header contain information about the run time version used for building the assembly, public key etc.
3. CIL Code – CIL code are actual implementation of code in terms of instructions. CIL code is described in length below.
4. Type Metadata – Describes the types contained within the assembly and the format of types referenced by that assembly.
5. An Assembly Manifest-Describes the modules within the assembly, the version of the assembly,all the external assemblies reference by that assembly.
Common Intermediate Language
CIL is a low level language based on the Common language Infrastructure specification document. (http://www.ecma-international.org/publications/standards/Ecma-335.htm). CIL was earlier referred as MSIL(Microsoft Intermediate Language) but later changed to CIL to standardize the name of the language which is based on the Common Language Infrastructure specification.
The source code from high-level language (C#, Basic or other language) is compiled in CIL and stored into an assembly.
The assembly is stored in a file in the PE (Portable Executable) format, which is also that of .dll and .exe, and includes a manifest file containing the medadata of the assembly, which is the interface of the code with other components of the software that uses it.
This code is compiled into bytecode to be interpreted by a JIT, or binary to be executed directly by the processor.
CIL is CPU and platform-independent instructions that can be executed in any environment supporting the Common Language Infrastructure, such as the .NET run time or the cross-platform Mono run time. These instructions are later processed by run time compiler and is then converted into native language. CIL is an object-oriented assembly language, and is entirely stack-based.
Assembly manifest
An assembly manifest is an XML file that describes a side-by-side assembly. Assembly manifests describe the names and versions of side-by-side assemblies, files, and resources of the assembly, as well as the dependence of the assembly on other side-by-side assemblies. Correct installation, activation, and execution of side-by-side assemblies requires that the assembly manifest always accompany an assembly on the system.
Garbage Collection (GC)
garbage collection (GC) is a form of automatic memory management. The garbage collector, attempts to reclaim memory occupied by objects that are no longer in use by the program.
For the majority of the objects that your application creates, you can rely on the .NET Framework’s garbage collector to implicitly perform all the necessary memory management tasks. However, when you create objects that encapsulate unmanaged resources, you must explicitly release the unmanaged resources when you are finished using them in your application. The most common type of unmanaged resource is an object that wraps an operating system resource, such as a file, window, or network connection. For these types of objects, the .NET Framework provides the Object.Finalize method, which
How do you enforce garbage collection in .NET? System.GC.Collect();
The oldest objects are at the lowest addresses (managed heap bottom), while new objects are created at increasing addresses (managed heap top).
Periodically the managed heap is compacted by removing dead objects and sliding the live objects up toward the low-address end of the heap.
The .NET Framework’s garbage collector manages the allocation and release of memory for your application. Each time you create a new object, the common language runtime allocates memory for the object from the managed heap. As long as address space is available in the managed heap, the runtime continues to allocate space for new objects. However, memory is not infinite. Eventually the garbage collector must perform a collection in order to free some memory. The garbage collector’s optimizing engine determines the best time to perform a collection, based upon the allocations being made. When the garbage collector performs a collection, it checks for objects in the managed heap that are no longer being used by the application and performs the necessary operations to reclaim their memory.
The GC generations
All the living objects from the managed heap are divided in three groups by their age. Those groups are generically called “Generations”.
.Net Framework
ADO.NET
All these years, Microsoft has been providing different ways to communicate with the Database. Developers have been switching from one data access technology to the other, starting with DAO (Data Access Objects), then RDO (Remote Data Objects), then ADO (ActiveX Data Objects) and then finally ADO.NET.