Language:

Search

Dot Net Core Interview Q & A - Set 1

  • Share this:

1. What do you understand by .NET Core Framework? [1]

.NET Core is a cross-platform, open-source framework that is the successor of .NET for building various types of applications, including web, desktop, and console applications. It provides runtime, libraries, and development tools for building and running .NET applications on different platforms.
.NET Core supports multiple programming languages, including C#, F#, and Visual Basic.

2. What is CoreCLR? [1]

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.

3. What is Kestrel? [1]

Kestrel is an event-driven, I/O-based, open-source, cross-platform, and asynchronous server that hosts .NET applications. It is provided as a default server for .NET Core therefore, it is compatible with all the platforms and their versions that .NET Core supports.

4. Describe the components of .NET Core. [1]

Common Language Runtime (CLR): It is the runtime environment that manages the execution of .NET Core applications. It provides features such as memory management, exception handling, garbage collection, and type safety.
Base Class Library (BCL): It is a collection of reusable classes, types, and APIs that provide fundamental functionality for building .NET Core applications.
CoreFX: CoreFX is a foundational set of libraries that complement the Base Class Library and provide additional functionality for building .NET Core applications.
ASP.NET Core: It is a cross-platform web framework for building modern web applications and services. It includes features for building web APIs, MVC web applications, real-time web applications using SignalR, and more.
Entity Framework Core: It is an object-relational mapping (ORM) framework that enables developers to work with databases using .NET objects. It provides a powerful set of APIs for querying, updating, and managing database data using .NET Core applications.
CLI (Command-Line Interface): The .NET Core CLI provides a command-line interface for creating, building, running, and managing .NET Core applications.
.NET Standard: .NET Standard is a formal specification that defines a set of APIs that must be available on all .NET implementations, including .NET Core, .NET Framework, and Xamarin.
Tooling: .NET Core includes a set of development tools, including Visual Studio, Visual Studio Code, and various command-line tools, that help developers build, debug, and deploy .NET Core applications efficiently.

5. What are NuGet packages? [1]

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 other words, 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.

6. What are service lifetimes in .NET Core? [1]

In .NET Core, service lifetimes define how long instances of services managed by the built-in dependency injection container (DI container) should live within the application. The choice of service lifetime affects how instances are created, reused, and disposed of by the DI container.

There are three types of service lifetimes supported by .NET Core:

service lifetimes in .NET Core

To specify the service lifetime when registering services with the DI container in .NET Core, you use the appropriate extension methods:

AddTransient: Registers a transient service.
AddScoped: Registers a scoped service.
AddSingleton: Registers a singleton service.

7. What do you know about .NET Core middleware? [1]

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. It is also responsible for giving responses or processing the request before and after it passes the pipeline.

8. Explain the concept of dependency injection in .NET Core. How does it differ from other dependency injection frameworks you have used? [1]

Dependency injection (DI) in .NET Core is a technique for achieving Inversion of Control (IoC) between classes and their dependencies. It promotes loose coupling, testability, and maintainability by allowing the runtime to provide required dependencies instead of hardcoding them within classes.

.NET Core’s built-in DI container differs from other frameworks like Autofac or Ninject in its simplicity and lightweight nature. While it provides basic features such as constructor, property, and method injection, it lacks advanced capabilities like interception or auto-registration. However, it can be easily replaced with third-party containers if needed.

In .NET Core, services are registered in the ConfigureServices method of the Startup class using IServiceCollection extension methods like AddTransient, AddScoped, and AddSingleton. These methods define the lifetime of the service instances.

9. In what situations .NET Core and .NET Standard Class Library project types will be used? [1]

.NET Core library is used if there is a requirement to increase the surface area of the .NET API which your library will access, and permit only applications of .NET Core to be compatible with your library if you are okay with it.

.NET Standard library will be used in case you need to increase the count of applications that are compatible with your library and reduce the surface area(a piece of code that a user can interact with) of the .NET API which your library can access if you are okay with it.

10. What is .NET Core CoreFX? [2]

CoreFX is the introductive class library for .NET Core. It consists of collection types, file systems, console, JSON, and XML for class library implementation. You can use this code as a single portable assembly. Since it provides platform-neutral code, thus you can share it across different platforms.

11. What is routing in .NET Core? [2]

It is a process through which the incoming requests are mapped to the corresponding controllers and actions.  The .NET Core MVC has a routing middleware to perform this task. This middleware matches the incoming HTTP requests to the executable request-handling code. We can define the routing in the middleware pipeline in the ‘Startup.Configure’ file.

As we can see in the below code snippet, there are two methods or pair of middleware to define routing:

UseRouting: Adds route which matches the middleware pipeline.
UseEndpoints: Adds end execution point to the middleware pipeline and runs the delegate of the endpoint.

12. What is Scaffolding in ASP.NET MVC?

One of the essential concepts of ASP.NET MVC that help developers like me generate code to perform basic operations – Create, Read, Update, Delete. You can make changes in the codes as per needs. That's why, we call it a "code-generation framework" for developing MVC applications. It helps enhance the code which interacts with the data model of applications. It also supports reducing the development time to execute data operations.

Additionally, the framework includes multiple templates, including page templates, field templates, , entity page templates, and filter templates. You can call them Scaffold templates. These templates permit you to design and build a fully functional website.

13. What is the role of middleware in ASP.NET Core? [3]

Intercepts HTTP requests and responses
Processes requests in a configurable pipeline
Offers built-in features like authentication, logging, and compression
Allows custom middleware for specific application needs
Extends functionality without modifying the core framework

14. What is the Options Pattern and how is it used in ASP.NET Core configuration? [3]

The Options Pattern is a design pattern used in ASP.NET Core to manage and load configuration settings from various sources, primarily the appsettings.json file. It works by:

Defining strongly typed classes: You create classes with properties representing your configuration settings. This provides type safety and better code readability.
Binding configuration: You use the IOptions interface to bind the corresponding section of the configuration file to your options class.
Dependency Injection: You register the IOptions service in the Dependency Injection (DI) container. This allows your code to access the configuration data throughout the application.

15. Describe how Routing works in ASP.NET Core and its different types. [3]

Routing in ASP.NET Core acts like a map, directing incoming requests to the right destination.
It matches the URL path against predefined templates in two main ways: convention-based (like "/Products/{id}" for product details) and attribute-based (using [Route] annotations on controllers).
These routes can be named for easier navigation and URL generation.
Convention-based routing kicks in first, followed by attribute-based, ensuring flexibility and control.
This dynamic system lets you build clean, intuitive URLs for your users.

There are two main ways to define routes in ASP.NET Core:

Convention-Based Routing

It creates routes based on a series of conventions representing all the possible routes in your system. Convention-based is defined in the Startup.cs file.

Attribute Routing

It creates routes based on attributes placed on the controller or action level. Attribute routing provides us more control over the URL generation patterns which helps us in SEO.

Attribute Routing Tokens

One of the cool things about ASP.NET Core routing is its flexibility as compared to ASP.NET MVC5 routing since it provides tokens for [area], [controller], and [action]. These tokens get replaced by their values in the route table.


16. What problems does Dependency Injection solve in ASP.NET Core? [3]

Dependency Injection (DI) addresses several key problems in ASP.NET Core, leading to a more robust and maintainable application:

Tight Coupling.
Code Rigidity.
Testing Difficulties.
Maintainability Challenges.

17. What is JIT? [4]

JIT stands for Just In Time. It is a compiler that converts the intermediate code into the native language during the execution.

18. Explain the differences between value type and reference type. [4]

The main differences between value type and reference type are given below:

A Value Type holds the actual data directly within the memory location and a reference type contains a pointer which consists of the address of another memory location that holds the actual data.
Value type stores its contents on the stack memory and reference type stores its contents on the heap memory.
Assigning a value type variable to another variable will copy the value directly and assigning a reference variable to another doesn’t copy the value, instead, it creates a second copy of the reference.
Predefined data types, structures, enums are examples of value types. Classes, Objects, Arrays, Indexers, Interfaces, etc are examples of reference types.


19. What is an assembly? [4]

An assembly is a file that is automatically generated by the compiler which consists of a collection of types and resources that are built to work together and form a logical unit of functionality. We can also say, assembly is a compiled code and logical unit of code.

Assemblies are implemented in the form of executable (.exe) or dynamic link library (.dll) files

20. What is caching? [4]

Caching means storing the data temporarily in the memory so that the data can be easily accessed from the memory by an application instead of searching for it in the original location. It increases the speed and performance efficiency of an application.

There are three types of caching:

Page caching
Data caching
Fragment caching

21. What is a delegate in .NET? [4]

A delegate is a .NET object which defines a method signature and it can pass a function as a parameter.

Delegate always points to a method that matches its specific signature. Users can encapsulate the reference of a method in a delegate object.

When we pass the delegate object in a program, it will call the referenced method. To create a custom event in a class, we can make use of delegate.

22. What is .NET Core SDK? [4]

.NET Core SDK is a set of tools and libraries that allows the developer to create a .NET application and library for .NET 5 (also .NET Core) and later versions. It includes the .NET CLI for building applications, .NET libraries and runtime for the purpose of building and running apps, and the dotnet.exe(dotnet executable) that runs CLI commands and runs an application

23. What is MSBuild in the .NET Core? [4]

MSBuild is the free and open-source development platform for Visual Studio and Microsoft. It is a build tool that is helpful in automating the software product creation process, along with source code compilation, packaging, testing, deployment, and documentation creation. Using MSBuild, we can build Visual Studio projects and solutions without the need of installing the Visual Studio IDE.

In the Universal Windows Platform(UWP) app, if you open the folder named project, you will get to see both files namely project.json and *.csproj. But if you open our previous Console application in .NET Core, you will get to see project.json and *.xproj files

24. What is the difference between .NET Core and Mono? [5]

Mono is third party implementation of .Net Framework for Linux/Android/iOs
.Net Core is Microsoft's own implementation for same

25. What's the difference between SDK and Runtime in .NET Core?  [5]

The SDK is all of the stuff that is needed/makes developing a .NET Core application easier, such as the CLI and a compiler.

The runtime is the "virtual machine" that hosts/runs the application and abstracts all the interaction with the base operating system.

26. How do you handle errors in .NET Core? [6]

.NET Core provides a built-in middleware for handling errors called the Exception Handling Middleware. Developers can also write custom middleware to handle specific types of errors.

27. What is a namespace in .NET? [6]

In .NET, a namespace is a way to organize and group related classes, structures, interfaces, enumerations, and other types within a common naming context. It provides a way to avoid naming conflicts between types and helps in better organization of the code.

28. What is the role of the Startup class in .NET Core? [6]

The Startup class is a fundamental component of the .NET Core web application architecture. It is responsible for configuring the application and its dependencies.

When the application starts, the Startup class is executed, and it performs the following tasks:

Sets up the environment: The Startup class sets up the hosting environment for the application, such as development, staging, or production. It also loads the configuration settings for the application.
    
Configures services: The Startup class is responsible for configuring the services that the application needs to function correctly.

Although it is not being embedded now, there is a file known as Program.cs file that performs the same operation as Startup.cs. However, you can create your own Startup.cs.

29. What is middleware in .NET Core? [6]

In .NET Core, middleware is a software component that sits between a web application's client-side and server-side components. It is responsible for processing incoming HTTP requests and generating appropriate HTTP responses. Middleware is a key feature of the ASP.NET Core framework, which is used to develop web applications.


30. What are the benefits of using ASP.NET Core over ASP.NET? [7]

ASP.NET Core comes with the following benefits over ASP.NET.

    Cross platform, provide ability to develop and run on Windows, Linux and MacOS.
    Open-source
    Side-by-side versioning
    Unified Platform to develop Web UI and services.
    Built-in dependency injection.
    Ability to deploy on more than one server like IIS, Kestrel, Nginx, Docker, Apache etc
    cloud enabled framework, provide support for environment based configuration systems.
    Lightweight, High performance and modern HTTP request pipelines.
    Well suited architecture for testability
    Integration of many client-side frameworks like Angular any version
    Blazor allow you to use C# code in browser with JavaScript code.

===============


Sources:

1. https://www.dotnettricks.com/tutorial/net/dotnet-core-interview-questions
2. https://www.hackertrail.com/talent/backend/net-core-interview-questions-answers/
3. https://www.scholarhat.com/tutorial/aspnet/asp-net-core-interview-questions
4. https://www.interviewbit.com/dot-net-interview-questions/
5. https://www.fullstack.cafe/blog/dot-net-core-interview-questions-and-answers
6. https://www.naukri.com/code360/library/net-core-interview-questions
7. https://www.qfles.com/interview-question/asp-net-core-interview-questions

Siva P SV

Siva P SV

I am developer and blogger. I am experienced in PHP, .NET, Android, Ionic, I know these kind of language. Because, I would like to learn new things in this world. I am still learning much more things. Oh, I forgot to mention that I am also one of the Co-Founders of Tuty Rocks