.NET Core Interview Questions and Answers for Experienced Developers

Explore 60+ .NET Core interview questions and answers covering ASP.NET Core, Entity Framework Core, Dependency Injection, Middleware, Authentication, Microservices, and advanced concepts.

1. .NET Core Fundamentals

What is .NET Core, and how is it different from .NET Framework?

.NET Core (now unified as .NET 5+) is a free, open-source, cross-platform framework for building modern applications.

  • Cross-platform: Runs on Windows, Linux, and macOS (Framework is Windows-only).
  • Open source: Developed on GitHub.
  • Modular: Uses NuGet packages instead of one large framework install.
  • Performance: Significantly faster due to a re-engineered runtime and JIT.
  • Side-by-side versioning: Multiple versions can run on the same machine.
  • Unified platform: Since .NET 5, Core, Framework, Xamarin, and Mono converged into one .NET.

What is CLR and CoreCLR?

CLR (Common Language Runtime) is the execution engine that manages memory, security, exception handling, and JIT compilation for .NET Framework applications. CoreCLR is the cross-platform runtime used by .NET Core, designed for portability and performance.

What is CTS and CLS?

  • CTS (Common Type System): Defines how types are declared, used, and managed in the runtime.
  • CLS (Common Language Specification): A subset of CTS rules that ensures interoperability among .NET languages.

What is the difference between .NET Standard and .NET Core?

.NET Standard is a specification containing a set of APIs implemented by multiple .NET platforms. .NET Core is an actual runtime and framework implementation.

What is the Common Language Infrastructure (CLI)?

CLI is an ECMA-335 specification describing executable code and the runtime environment for .NET languages.

What are the different types of .NET Core project templates?

  • Console App
  • Class Library
  • ASP.NET Core MVC
  • ASP.NET Core Web API
  • Blazor Server
  • Blazor WebAssembly
  • Worker Service
  • xUnit Test Project
  • NUnit Test Project
  • gRPC Service

What is Kestrel?

Kestrel is the default lightweight, high-performance, cross-platform web server used by ASP.NET Core.

What is the difference between .NET Core CLI and Visual Studio?

The dotnet CLI is a cross-platform command-line tool used to create, build, test, run, and publish applications. Visual Studio is an IDE that provides a graphical interface, debugging tools, designers, and integrated development features.

2. Project Structure & Configuration

What is the role of Program.cs and Startup.cs?

  • Program.cs: Entry point of the application that builds and runs the host.
  • Startup.cs: Used in .NET 5 and earlier to configure services and middleware. In .NET 6+, Startup functionality is integrated into Program.cs.

What is appsettings.json, and how does configuration work in .NET Core?

appsettings.json stores application configuration settings. .NET Core supports multiple configuration providers such as:

  • appsettings.json
  • appsettings.{Environment}.json
  • Environment Variables
  • Command-Line Arguments
  • User Secrets
  • Azure Key Vault

Configuration is accessed using IConfiguration and can be mapped to strongly typed classes using the Options Pattern.

What is the difference between IOptions<T>, IOptionsSnapshot<T>, and IOptionsMonitor<T>?

  • IOptions<T>: Singleton configuration loaded once.
  • IOptionsSnapshot<T>: Scoped configuration refreshed per request.
  • IOptionsMonitor<T>: Singleton configuration supporting real-time updates.

What are environments in ASP.NET Core?

ASP.NET Core supports Development, Staging, and Production environments controlled through the ASPNETCORE_ENVIRONMENT variable.

3. Dependency Injection

What is Dependency Injection, and how is it implemented in .NET Core?

Dependency Injection (DI) is a design pattern where dependencies are supplied externally rather than instantiated inside classes. .NET Core provides a built-in IoC container for registering and resolving dependencies.

What are the service lifetimes available in Dependency Injection?

  • Transient: New instance every time requested.
  • Scoped: One instance per HTTP request.
  • Singleton: One instance throughout application lifetime.

What happens if a Scoped service is injected into a Singleton?

It creates a captive dependency problem because the scoped service may outlive its intended request scope and cause stale data or threading issues.

Can third-party DI containers be used?

Yes. DI containers such as Autofac, Ninject, and StructureMap can replace the default container.

4. Middleware & Request Pipeline

What is Middleware in ASP.NET Core?

Middleware components process HTTP requests and responses in a pipeline. Each middleware can execute logic before and after the next middleware.

What is the difference between Use, Run, and Map?

  • Use: Adds middleware and can call the next delegate.
  • Run: Terminal middleware that ends the pipeline.
  • Map: Creates a branch in the pipeline based on URL path.

How do you create custom middleware?


public class RequestLoggingMiddleware
{
    private readonly RequestDelegate _next;

    public RequestLoggingMiddleware(RequestDelegate next)
    {
        _next = next;
    }

    public async Task InvokeAsync(HttpContext context)
    {
        await _next(context);
    }
}

app.UseMiddleware<RequestLoggingMiddleware>();

What is the recommended middleware order?

Exception Handling → HSTS → HTTPS Redirection → Static Files → Routing → CORS → Authentication → Authorization → Endpoints

12. Quick-Fire Conceptual Questions

Question Answer
What is Boxing/Unboxing? Converting a value type to object (boxing) and converting it back (unboxing).
Difference between const and readonly? const is compile-time constant, readonly is assigned at runtime.
What is a delegate? A type-safe function pointer.
What are Events? A wrapper around delegates implementing the observer pattern.
Difference between IEnumerable and IQueryable? IEnumerable executes in memory, IQueryable executes at the data source.
Difference between abstract class and interface? Abstract classes can contain implementation and state, interfaces mainly define contracts.
What is Reflection? Inspecting and manipulating assemblies, types, and members at runtime.
Difference between String and StringBuilder? String is immutable while StringBuilder is mutable.
What is Nullable Reference Type? A C# feature that helps detect potential null reference issues.
Dependency Inversion vs Dependency Injection? Dependency Inversion is a design principle; Dependency Injection is a technique used to implement it.