Basic .NET Core Interview Questions and Answers
What is .NET Core Framework?
.NET Core is an open-source web development framework that is the successor of .NET and both are maintained by Microsoft.
.NET Core is also cross-platform meaning that you can use it on multiple operating systems/ platforms- Linus, macOS, and Windows. Its important features include sharable core libraries and others that come as NuGet packages. You can add the packages as needed to optimize the performance of the application, make it easier to maintain, and decrease its memory footprint. It follows a more modular approach in comparison to its predecessor, i.e. instead of installing the whole of the .NET framework, you can just install or use what is required. Also, .NET Core comes with base class libraries whose code is largely similar to that of .NET Framework class libraries.
What are the common uses of .NET Core?
Some important uses of .Net Core are:
- To create and develop server applications and web applications functional across multiple operating systems.
- To write libraries in both runtimes using languages like C#, VB.NET, and F#.
- To build mobile backends, cloud applications, and IoT applications
- Desktop application development and to develop microservices out of large enterprise applications
- Its flexibility, lightweight features, and high performance make it possible to deploy .NET Core applications in containers extremely quickly.
Mention the latest version of .NET Core and any important features.
The latest version is .NET 6 which was released in November 2021. One unique attribute of the version is that it unifies the base libraries, SDK, and runtime across desktop, mobile, cloud, and IoT apps.
Differentiate between .NET and .NET Core?
.NET Core Framework | .NET Framework |
It is open-source | Some of its components are open-source |
Runs across multiple operating systems- Windows, macOS, and Linux, i.e. is cross-platform | Runs only on Windows, i.e. is not cross-platform |
Has better support | Relies heavily on command line tools |
Is flexible in installation, i.e. you can install components on a needed bases | Must be installed as a whole package |
Is faster, high-performance, and easier to scale | Less effective in comparison to .NET Core |
.NET Core ships in smaller NuGet packages | .NET Framework ships as a whole package |
What languages can you use on .NET Core?
Developers can use multiple programming languages including C++, C#, F#, Visual Basic, etc to work in the framework and develop .NET Core applications. The Microsoft Intermediate Language (MSIL) and Common Language Infrastructure (CLI) make it possible to transform any programming language into CPU-independent instructions.
How is Mono different from .NET Core?
.NET Core is a part of the .NET framework developed and maintained by Microsoft to facilitate the development of modern applications and other developer workflows. Mono is also an extension of the .NET framework, but this has been optimized by Xamarin, for Android, Windows, iOS, and macOS. The base library for .NET Core is CoreFX Class Library, and for Mono is Mono Class Library.
What is CoreCLR?
The CLR is the execution/ run-time engine in .NET Core, that is, it is responsible for the execution and running of programs in different programming languages. It consists of the following major components:
- Garbage collector
- JIT compiler
- Low-level classes
- Primitive data types.
- CLS and CTS
The Common Language Runtime (CLR) performs the garbage collection and code compilation functions etc.
What is CTS?
CTS or Common Type System is responsible for cross-language integration, high-performance code execution, and type safety of a code. It defines datatypes, and how these types are declared and managed during the runtime of a code or an application. All programming languages have their own data type, and these cannot be understood by other languages. But CTS enables the .NET framework to understand all data types.
CTS is a single-rooted object hierarchy where the System object is the base type for the derivation of all other types. Two major kinds of types it supports are:
- Value Types: These types are either allocated within the structure inline or are stored directly in the stack. This includes built-in value types (standard primitive types), types defined in source code, user-defined value types, enumerations, etc.
- Reference Types: These store value memory address references and are allocated on the heap. They may be any of the interface types, pointer types, or self-describing types. For example- class types and arrays like boxed value types, delegates, user-defined classes, etc.
What is Kestrel?
Kestrel is a cross-platform web server that is enabled by default in ASP.NET Core project templates. It supports- HTTPS, HTTP/2, opaque upgrade (to enable WebSockets), and Unix sockets. It is supported on all versions and platforms of .NET Core.
What is CoreFX?
CoreFx is the term used to refer to the foundational/ introductory class libraries for the .NET Core.CoreFX consists of collection types, class types, consoles, XML, and JSON for class library implementations. This results in platform-neutral code which can be used as a single portable assembly.
Is Garbage collection an ongoing process? When does it occur?
Yes, Garbage collection is an ongoing process that occurs in any of the following situations:
- Low physical memory
- When memory space used by allocated objects surpasses an acceptable threshold
- When the GC. Collect method is called, however, this only happens in rare testing situations since Garbage collection in itself is an ongoing process.
What is MSIL?
MSIL stands for Microsoft Intermediate Language. Whenever we compile .NET codes, it is first converted to MSIL code, which then CLR interprets. The MSIL code is hardware and operating system independent.
What is the key difference between Runtime and SDK in .NET Core?
The major difference between .NET Core SDK and .NET Core Runtime is that the former is functional in the building/ development of applications, while the latter is a virtual machine responsible for the application execution and running.
What is .NET Core SDK?
The set of tools and libraries used in the development process is referred to as SDK. They help developers in creating .NET Core libraries and applications.
What do you mean by .NET Core middleware?
A middleware is a component of an application pipeline that handles requests and responses. That is, the middleware component chooses whether or not to pass an incoming request to the next component of the pipeline. And it is also responsible for giving responses or processing the request before and after it passes the pipeline.
What is .NET Standard?
The .NET standard is a set of APIs meant to establish unity in the .NET ecosystem. It does this by compiling the base class libraries for different frameworks/ platforms. In simple terms, it creates a single uniform layer and set of APIs which support the whole of the .NET ecosystem.
List the most important characteristics of .NET Core?
The most important features of .NET Core are-
Open-source platform: The framework as mentioned before is open-source i.e. the source code is freely available, is maintained by Microsoft, and uses Apache 2 and MIT licenses.
Supports multiple programming languages: The framework supports multiple programming languages and can be used to develop apps across multiple platforms.
Cross-platform: .NET core supports and is executable on multiple platforms- Linux, Windows, and macOS. It is quite simple to port a code from one platform to the other.
Flexible: It is flexible in terms that it allows you to include/ install desired codes on a requirement basis.
What is ASP.NET Core?
ASP stands for Activ Server Pages which refers to any framework meant for building web pages. In line with this, ASP.NET is an extension of the .NET platform, that is, it adds tools and libraries to the framework for the specific purpose of building web applications. ASP.NET Core, released in 2016, is a redesign of ASP.NET.
ASP.NET Core is modular and leaner than ASP.NET. It merges ASP.NET Model-View-Controller (MVC), ASP.NET Web Pages, and ASP.NET API in one application framework.
Are ASP.NET Core and .NET Framework compatible?
Yes, ASP.NET Core works with both the .NET framework and the .NET Core framework and is managed by Microsoft.
What is a Garbage Collector (GC)?
Garbage collection refers to the process of collection or removal of programs that are no longer in use thus freeing up memory space. A garbage collector carries on this function and may be thought of as an automatic memory manager.
Mention the main architectural components of .NET Core
There are 3 main architectural components:
- .NET Core Runtime- The main purpose is to ensure the smooth functioning of the app/ program by providing type safety, native interop services, assemblies, garbage collection, etc.
- Framework Libraries- These include base libraries with components like app composition types and other fundamental utilities.
- SDK compilers (Roslyn) and command line tools- These facilitate quick development of programs/ applications on .NET Core
What is meant by Razor Pages?
Razor Pages is a comparatively newer and more simplified web app development/ programming model. The Razor Pages follow a file-based routing approach thus simplifying the "Model-View-Controller" architectural model of ASP.NET. The code and the HTML are both in a single file which eliminates the need for separate view models, controllers, action methods, etc.
What is unit testing?
Unit testing is the process of breaking the program down into small bits of code at the functional level, called units. The units are then tested to ensure that they return the value one expects. An advantage of the unit testing framework is that automates the process and keeps testing the program as it is being built.
What are NuGet packages?
NuGet packages are parts of the package management system for .NET which are essential to carry on any development on the platform. These packages contain libraries and other descriptive metadata and are managed by NuGet.
In simpler terms, a NuGet package is a single zip file with a .nupkg extension. The file contains compiled codes, files related to the code, and descriptions. Developers can create and share these packages by publishing them to either private or public hosts. They can also use the packages available and add to projects on an as-needed basis.
What are Empty migrations?
When you want to add migrations without making any changes in the model it might lead to the creation of code files with empty classes. These can be customized to perform operations not related to the core Entity Framework (EF) model.
What is Explicit Compilation (Ahead of time)?
Explicit compilation refers to the process of converting upper-level language into project code before interaction or project execution. This is why explicit compilation is also referred to as ahead-of-time (AOT) compilation, as in, before interaction between the CPU and program.
Mention a few benefits of AOT
Some benefits of AOT are:
- It leads to a smaller application size (exclusive of the angular compiler)
- Component rendering becomes quicker
- The template parse errors are detected early at the build time
- The program is more secure since there is no need to dynamically evaluate templates
Explain Docker in .NET Core
Docker is a service container that is used to develop and publish applications. Application developers can package their applications in docker containers which can then easily be managed with git and can be synchronized across machines. These containers are lightweight and include everything needed to run the respective application without dependencies.
What is the IGCToCLR interface?
The IGCToCLR interface is used to communicate with the runtime environment. It passes an argument to the InitializeGarbageCollector function.
What is a class library? Mention its types and methods.
A class library is a compilation of pre-written code templates and classes which developers can refer to and use when developing an application. Any class library that is developed with .NET Core supports the .NET Standard Library. It can then be called onto by any platform which supports that .NET Standard Library.
The method to create a class library is- Right click on the solution, select Add --> New Project --> .NET Standard --> Class Library and select a class library template. Then give the project a name and select a folder to store it, this will create the library. You can then add properties to the library and change its settings as needed.
Visual Studio, the integrated development environment for Windows supports four types of class library templates- .NET Framework, .NET Core, .NET Standard, and Universal Class Library.
What is the purpose of webHostBuilder()
The webHostBuilder() as the name suggests is a factory used to create a web host for a web application. This function also configures the bits needed by the web host to run the application. It is a part of Microsoft.AspNet.Hosting namespace.
Why would you generate SQL scripts in .Net core?
When you want to add migrations, you will have to deploy and apply them to the database to bring it to action. This is where you need to generate SQL scripts that ensure accuracy in the application of the migrations and consequent schema changes of the databases.
How do you decide when to use .NET Standard Class Library as against .NET Core Library
When you use the .NET Standard library type you will reduce the .NET surface area and at the same time increase the number of apps that are compatible with your library.
You should use the .NET Core library type when the motive is to increase the .NET API surface area. But remember this also limits the compatibility of the library to only .NET Core applications.
Explain the difference between Task and Thread in .NET
In simple terms, a task is something you want to get done, and a thread is a way to accomplish it. So in this sense, a thread is a part of the task.
A thread represents the smallest unit of code processing at the OS level, with stacks and kernels. You can exercise a high degree of control over threads with Suspend() or Abort() or Resume() a thread. ThreadPool, as the name suggests is a wrapper comprising a pool of threads maintained in the runtime environment by CLR.
A task in comparison is executed by a TaskScheduler and cannot create its own OS threads. A default scheduler runs on the ThreadPool and also lets you know when the task finishes and returns a result.
What's the difference between RyuJIT and Roslyn?
Roslyn is a .NET Core compiler that compiles VB or C# code to the intermediate language (IL). Whereas, RyuJIT as the name suggests is a Just-In-Time compiler that works the other way around i.e. compiles the IL to native code.
Explain the meaning of state management
In simple terms, state management refers to the technique or process of maintaining the state of a page or application till the time the user's session ends. In .NET, state management refers to the object that controls the state of an object steady through different processes. Some common approaches followed for this include- cookies, cache, temp data, query strings, etc.
Give a brief about Garbage Collection
Garbage collection is one of the most important features of high-level programming languages and frameworks. The feature is carried on by a garbage collector which automates the process of memory allocation and management.
There are three generations in the memory heap- zero (for short-lived objects), one (for medium-lived objects), and two (long-lived objects). The collection of garbage then refers to the collection of all the objects in different generations, that are no longer in use. The collector frees memory space by collecting these objects thus functioning as an automatic memory manager.
Garbage collection occurs in three situations- one when the physical memory is low, when the acceptable threshold is exceeded, or when the GC method is called on. The major benefits of this are that developers don't need to manually free up what memory space, or worry about efficient allocation of objects on the managed heap, and it ensures security/ safety by blocking one object from using the content of another object.
What is the hosting environment?
The hosting environment contains application-specific details such as application functions, where it is stored, services for app management, etc. A HostingEnvironment is created in the ApplicationDomain, before the ASP's creation. In other words, a hosting environment is responsible for application management and app-specific functions.
This feature of .NET Core makes it possible for the developer to work with multiple environments, without creating any friction.
What is .NET Core CLI?
CLI stands for Command Line Interface, which is a toolset used for developing/ building, running, and publishing all applications. You can also build .NET framework compatible libraries and Console applications with the command line. You don't need to install the CLI on the machine, since it is a part of the .NET SDK.
Explain response caching
Response caching is when the .NET Core MVC's HTTP responses are pre-specified in cache-related headers. These headers describe how intermediate or client machines should cache responses to requests. This hence reduces the volume of requests the client or proxy machine makes to the web server.
This brings us to the end of the list of top 50 dot NET core interview questions and answers that will help you ace your developer interview with ease. Check out the articles listed below to know more about some other interesting topics and some other QA banks.
What is JIT and how many types of JIT compilations do you know?
Programs called compilers to convert all source code into executable code before it is brought to action. This is called compilation, which is when compilers convert application code into machine instructions (also object code). There are two steps to the whole process- first where the source code is converted to IL by language-specific compilers, and the second is converting IL to machine instructions by JIT compilers. These are called JIT compilers because only the executed IL code fragments are compiled to machine instructions, that too at the runtime, or should we say just-in-time for execution.
The .NET has three types of JIT compilers, namely,
- Pre-JIT Compilers
- Econo JIT Compilers
- Normal JIT Compilers
Why is the Startup Class?
The Startup class in .NET Core contains the Configure methods and Configure services. Of these, the former helps configure the request processing pipeline, and the latter helps configure the required services.
What is the purpose of the IDisposable interface?
IDisposable interface is defined in the System namespace and it contains a single method- Dispose(). The purpose of this method is to release unmanaged resources from the application or class library. Some of these unmanaged resources might include database connections, fonts, streams, files, etc.
What is the difference between 'managed' and 'unmanaged' code?
The primary difference between the 'managed' and 'unmanaged' code is that for the former, the CLR in the .NET framework manages the code, while in the latter the operating system directly executes the code. Also, the 'managed' code adds a layer of security to the application not present in the case of 'unmanaged' code.
Is the 'debug' class the same as the 'trace' class?
They aren't the same thing. Debugging refers to the process of finding errors in a code. While tracing refers to the process of charting out the execution pathway of a code, or getting other execution information. The trace class is broader in comparison as it can be used for both releasing builds as well as debugging the code.
What is MEF in .NET Core?
MEF stands for Managed Extensibility Framework and it is a library used for developing lightweight extensible applications. With the MEF, developers can discover extensions and use them without the need for configuration. Many believe that MEF is no longer available in .NET Core, however, it has been ported to the .NET Core as the System.Composition.
What are UWP Apps in .Net Core?
UWP stands for Universal Windows Platform and it is one of the numerous ways of client application creation for Windows. The WinRT APIs used in these apps result in powerful UIs and advanced asynchronous features. The common features of these apps are that they are secure, use a common API, and can install and uninstall the apps without risking 'machine rot'.
What is MSBuild?
Microsoft Build Engine (MSBuild) is a VS and Microsoft open-source platform for building applications. It helps in the automation of the software creation process including code compilation, testing, packaging, documentation, and deployment.
What is CoreRT?
The CoreRTis the .NET Core toolset that is responsible for compilation to translation processes. It uses the ahead-of-compiler RyuJIT to compile CIL byte core to machine code.
Post a Comment