.NET Interview Questions and Answers

1. Which are the components of .net framework?

The .NET Framework is a software development platform developed by Microsoft, designed to create a wide range of applications, from web and desktop applications to services. Its architecture is built upon several core components that work together to provide a managed execution environment and a rich set of libraries for developers. The most fundamental component is the Common Language Runtime (CLR). The CLR acts as the execution engine for .NET applications. It manages essential tasks such as memory allocation and garbage collection, ensuring efficient resource utilization and preventing common programming errors like memory leaks. Furthermore, the CLR handles code execution, performs Just-In-Time (JIT) compilation to convert intermediate language (IL) code into native machine code, enforces code access security, manages exceptions, and ensures type safety, contributing to the robustness and security of applications built on the framework.

Another crucial component is the Framework Class Library (FCL), often referred to in part as the Base Class Library (BCL). The FCL provides a vast, organized collection of reusable classes, interfaces, and value types that developers can leverage to build applications more quickly and efficiently. This library covers a wide array of functionalities, including data structures, input/output operations, network communication, database interaction through technologies like ADO.NET, XML processing, and more. By providing pre-built code for common programming tasks, the FCL significantly simplifies development and promotes code reuse and consistency across applications.

Beyond the CLR and FCL, the .NET Framework includes specific application models tailored for different types of software development. For web development, ASP.NET provides a powerful framework for building dynamic websites, web applications, and web services. For desktop applications, developers historically used Windows Forms or the more modern Windows Presentation Foundation (WPF), which offer extensive UI controls and capabilities for creating rich client applications. While the original .NET Framework focused primarily on Windows, related .NET technologies extend capabilities to other platforms. The framework's design also emphasizes language interoperability, allowing developers to write code in various .NET-compliant languages like C#, VB.NET, or F#, which all compile down to the Common Intermediate Language (CIL) and utilize the same runtime and class libraries. This interoperability is facilitated by the Common Type System (CTS) and Common Language Specification (CLS), ensuring seamless integration between components written in different languages. Together, these components form a comprehensive and versatile platform for software development.

References:

2. What is assembly? What is manifest?

In the .NET ecosystem, an assembly serves as the fundamental building block for deployment, versioning, reuse, activation scoping, and security permissions. It represents a compiled, logical unit of code and resources designed to work together. Physically, an assembly typically manifests as a single file, either an executable (.exe) or a dynamic-link library (.dll), although it can also span multiple files. Each assembly contains compiled code in the form of Microsoft Intermediate Language (MSIL or CIL), which is the common language understood by the Common Language Runtime (CLR). Crucially, an assembly is self-describing; it embeds metadata that details the types (classes, interfaces, structures, enums, delegates) and resources defined within it, as well as its dependencies on other assemblies. This self-contained nature allows the CLR to load and execute the assembly without needing external information like registry entries, simplifying deployment and reducing conflicts.

The assembly manifest is an integral part of every assembly, containing vital metadata that describes the assembly itself. This metadata is essential for the CLR to manage the assembly correctly. The manifest includes the assembly's identity, which comprises its simple text name, a version number (major.minor.build.revision), an optional culture identifier, and an optional public key token if the assembly is strongly named (used for uniqueness and security). Furthermore, the manifest lists all the files that constitute the assembly (if it's a multi-file assembly), specifies the types that are exported from the assembly, and details the dependencies on other assemblies, including their required versions. This comprehensive metadata enables crucial runtime features like version binding (ensuring the correct version of a dependent assembly is loaded), type resolution, and security enforcement. Essentially, the manifest acts as a blueprint or table of contents for the assembly, providing all the necessary information for the .NET runtime to locate, load, and manage the assembly and its dependencies effectively throughout its lifecycle.

References:

3. What is GAC? How it handles DLL hell problem?

The Global Assembly Cache (GAC) is a machine-wide repository maintained by the .NET Framework's Common Language Runtime (CLR) specifically designed to store assemblies that are intended to be shared among multiple applications installed on the same computer. Unlike private assemblies, which are typically deployed within an application's directory, assemblies placed in the GAC are accessible globally to any .NET application running on that machine. To be eligible for installation into the GAC, an assembly must possess a strong name. A strong name provides a unique identity consisting of the assembly's simple text name, its version number, culture information (if applicable), and a public key token derived from the publisher's public/private key pair. This strong naming ensures the assembly's uniqueness and provides a level of security and integrity, guaranteeing that the assembly hasn't been tampered with and originates from the expected publisher.

The GAC plays a crucial role in mitigating the infamous "DLL Hell" problem, a common issue in older Windows development environments where multiple applications could conflict due to dependencies on different versions of the same shared Dynamic Link Library (DLL). DLL Hell often arose when installing a new application overwrote a shared DLL with a newer, potentially incompatible version, breaking existing applications that relied on the older version. The .NET Framework, through the GAC and its versioning mechanism, addresses this challenge effectively. By allowing multiple versions of the same strongly-named assembly to coexist within the GAC, .NET ensures that each application can load the specific version of a shared assembly it was compiled and tested against. When an application needs to load a shared assembly, the CLR checks the GAC first. If the required version (identified by its strong name) is present, the CLR loads it from the GAC, isolating the application from version conflicts that might arise from other applications using different versions of the same assembly. This side-by-side versioning capability, enabled by strong naming and the centralized management provided by the GAC, significantly reduces the likelihood of DLL Hell scenarios for shared components in the .NET ecosystem.

References: