Loading, please wait...

A to Z Full Forms and Acronyms

Frequently asked : DotNet Core Interview questions and Answers

The objective of this article is to make a list of Dot Net Core interview questions and their answers. So, It can help those peoples who are preparing for interview.

The objective of this article is to make a list of Dot Net Core interview questions and their answers. So, It can help those peoples who are preparing for an interview also we'll suggest you check out a big collection for Programming Full Forms that may help you in your interview:

List of Programming Full Forms 

Dot Net Core Interview Questions and Answers

Q1. What is the difference between .NET Core and .NET Framework?

Answer: Dotnet Core and the DotnetFramework have a subset-superset relationship. Dotnet Core is named "Core" as it contains the core features from the Dotnet Framework, for both the runtime and framework libraries.  For example, Dotnet Core and the Dotnet Framework share the GC, the JIT, and types such as String and List.

Dotnet Core is an open-source, cross-platform, high-performance framework for building modern, cloud-based, Internet-connected applications.

Q2. What are the new features the dot net core provides?

Answer: Below are new features provided by the dot net core framework

  • Dot net core introduced a new webserver called “Kestrel” which can work cross-platform, which means your web application can run on other platforms like Linux, Mac, etc.
  • It supports in-build dependency injection, you do not need to install any third party DLL for it.
  • Now dot net core unified the MCV controller and Api controller.
  • It is open-source. So the community can contribute.
  • Razor pages more code-focused
  • Side-by-side app versioning means If I have 2 applications A and B, A can target .NET Core 2.1 and B can target .NET Core 2.2.
  • It is lightweight and gives high performance.
  • You can host your application on IIS, Nginx, Docker, Apache, and self-Host.
  • Configure your appsettings.json based on the hosting environment.
  • Great support for the cloud.

Q3. What is Kestrel in Dot Net Core?

Answer: Kestrel is a fast, new cross-platform web server introduced in dot net core that can run your web application on Linux, macOS, etc.

You can set a kestrel server in the program.cs file

public static void Main(string[] args)
{
    var host = new WebHostBuilder()
        .UseContentRoot(Directory.GetCurrentDirectory())
        .UseKestrel()
        .UseIISIntegration()
        .UseStartup<Startup>()
        .ConfigureKestrel((context, options) =>
        {
            // Set properties and call methods on options
        })
        .Build();
    host.Run();
}

Q4. What is Startup.cs file in Dot Net Core?

Answer: Startup.cs file is the entry point of application that is must include in asp.net core application. It’s like global.asax in the old dot net framework. It contains two important methods, one is  “ConfigureServices” for configuring the application service or in other words use this method to add services to the container and the other one method is “Configure”  which is for configuring the HTTP request pipeline. Startup.cs class called from the program.cs file. Check below code

public class Startup
{
    // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services)
    { 
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app)
    { 
    }
}

public class Program
{
    public static void Main(string[] args)
     {
       CreateWebHostBuilder(args).Build().Run();
     }

     public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
            WebHost.CreateDefaultBuilder(args).UseKestrel()
                .UseStartup<Startup>();
}

Q5. What is the ConfigureServices method of the Startup.cs file?

Answer: ConfigureServices method gets call runtime to register services to DI container. After registering for the dependent classes, you can use those classes anywhere in the application. The ConfigureServices method includes the IServiceCollection parameter to register services to the DI container.

Q6. What is the Configure method of the Startup.cs file in Dot Net Core?

Answer: Configure the method gets call runtime to configure the HTTP request pipeline for application. Configure use the instance of the IApplicationBuilder that is provided by the In-Build IOC container. In other words, you add the middleware in this method like routing and other custom middleware as per your application requirements.

Q7. What is Dependency Injection in Dot Net Core?

Answer: The DotNet core has an In-build dependency mechanism. You have to add namespace Microsoft.Extensions.DependencyInjection in Startup.cs file to get enable IServiceCollection. In the ConfigureServices method, you can add your decencies to a container that will automatically resolve your dependencies and you can access your classes anywhere in the application. The built-in IoC container supports three kinds of lifetimes: 

  • Singleton: It creates and shares a single instance of service throughout the application's lifetime.
  • Transient: It creates a new instance of the specified service type every time when it requested. This lifetime works best for lightweight, stateless services.
  • Scoped: It creates an instance of the specified service type once per request and will be shared in a single request.

Q8. What is Middleware in Dot Net Core?

Answer: Middleware is a pipeline that handles requests and responses. Requests are passes through this pipeline where all middleware is configured and it performs an action before passing it to the next middleware. The following diagram shows the concept of middleware.

Q9. What is the environment variable in the Dot Net core?

Answer: If you are using more than one connectionString then you can take advantage to set an environment variable. You can create multiple appsetting.json files like appsettings.dev.json, appsettings.qa.json, etc. Following code for retrieving your environment variable which you can set in launchSettings.json

//To retrieve your environment variable
       static void ConfigConfiguration(WebHostBuilderContext ctx, IConfigurationBuilder config)
        {
            var env = ctx.HostingEnvironment;
            config.SetBasePath(env.ContentRootPath)
                .AddEnvironmentVariables()
                .AddInMemoryCollection()
                .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: false, reloadOnChange: true);
            config.Build();
        }

Q10. How to handle errors in middleware?

Answer: You can capture synchronous and asynchronous exception instances from the middleware pipeline and generate an HTML response. Following code has If the condition in which you can call different methods for development, staging, production environment or you can pass the environment name in IsInvironment extension method.

Also, you can configure a custom error handling page to call the UseExceptionHandler method that adds a middleware to a pipeline that will catch the exception, log them, Re-executes the request in an alternate pipeline for the page or controller indicated. The request isn't re-executed if the response has started.

if (env.IsDevelopment())
{
   app.UseDeveloperExceptionPage();
}
else
{
   app.UseExceptionHandler("/Error");
   app.UseHsts();
}

Q11. Where static files contains in the ASP.NET Core application?

Answer: There is a folder called "wwwroot", under this folder has several folders where you can find the CSS, js files.

wwwroot

  • CSS
  • js
  • lib

Q12. How many types of single page application templates provided by the Dot Net Core?

Answer: Following types of a single page, application templates are available in dot net core

  • Angular
  • React
  • React with Redux
  • JavaScript Services

Q13. What are tag helpers in ASP.NET Core?

Answer: Asp.net core provides an in-build tag helper, Tag helper enables the server-side code that creates and renders the HTML elements in the Razor page.

Example: 

<input asp-for="Email" class="form-control" />

Q14. Does real-time application support by Dot Net Core?

Answer: Yes, Asp.net's core signalR is an open-source library that gives real-time web functionality to the application.

Q15. What is the difference between app.Run and app.Use in ASP.NET Core middleware pipeline?

Answer: Both are used to add middleware delegate to the application request pipeline. 

app.Run(): Insert a middleware without invoking the next middleware. It is just run.

app.Use(): Insert a middleware into the pipeline which invokes the next middleware.

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
    app.Use(async (context, next) =>
    {
        await context.Response.WriteAsync("Return from app.Use");
        await next();
    });
    app.Run(async context => {

       await context.Response.WriteAsync("Return from app.Run");

    });

 //Below app.Use will not execute as app.Run does not execute next middleware
    app.Use(async (context, next) =>
    {
        await context.Response.WriteAsync("Return from app.Use");
        await next();
    });
}

Q16. What is launchSettings.json file in ASP.NET Core?

Answer: It holds the project-specific configuration to launch the application including the environment variable.

//launchSettings.json
{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:63977",
      "sslPort": 44389
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
  "TestApp": {
      "commandName": "Project",
      "launchBrowser": true,
      "applicationUrl": "https://localhost:5001;http://localhost:5000",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}

Q17. What are the Razor Pages in Asp.net Core?

Answer: Razor Pages is a new feature of ASP.NET Core that makes coding page-focused scenarios easier and more productive. The Razor Pages are lightweight and very flexible for building dynamic, data-driven web sites with a clean separation of concerns.

Q18. What are discontinued Technologies in .NET Core?

Answer:

  • Reflection
  • AppDomain
  • Remoting
  • Binary serialization
  • Sandboxing

Q19. What is WebListener?

Answer: WebListener is a web server for ASP.NET Core that runs only on Windows, based on the Windows Http Server API. It runs directly on the Http.Sys kernel driver. WebListener can be used for direct connection to the Internet without relying on IIS. It can only be used independently.

Q20. What are the new features that brought Dot Net core 2.2?

Answer:

  • OpenAPI Analyzers & Convention
  • Problem details support
  • New Endpoint Routing
  • NET Core 2.2 adds support for HTTP/2
  • Options to configure Kestrel
  • NET Core 2.2 introduces a Java Client for SignalR
  • The performance of SocketsHttpHandler was improved by reducing connection pool locking contention.
  • Validation performance

You can visit Microsoft documents for what new features have in Dotnet core 2.2

More Interview Questions and Answers:

A to Z Full Forms and Acronyms

Related Article