Fifteen common .NET interview questions
- What are the CLR, the JIT and the base class library?
- How does garbage collection work in .NET? What are generations?
- Value types versus reference types? Boxing?
- What does IDisposable do, and how does using help?
- How does async/await work? What causes async deadlocks?
- Task versus ValueTask?
- What are dependency injection lifetimes: transient, scoped, singleton?
- How does the ASP.NET Core middleware pipeline work?
- Minimal APIs versus controllers?
- How does configuration and the options pattern work?
- EF Core tracking versus no-tracking queries?
- How do you avoid N+1 queries in EF Core?
- How do EF Core migrations work?
- How do you handle errors and logging in ASP.NET Core?
- How do you improve the performance of a slow API?
Runtime fundamentals
- CLR: the runtime that executes intermediate language, compiled to native code by the JIT (or ahead of time with Native AOT).
- Garbage collection: generational — short-lived objects in generation 0 are collected cheaply and often; survivors are promoted. The large object heap holds big allocations.
- Value vs reference types: structs live inline and copy on assignment; classes are heap objects referenced by pointer. Boxing wraps a value type in an object and costs an allocation.
- IDisposable: releases unmanaged resources deterministically; using statements guarantee Dispose is called.
Async and dependency injection
await yields the thread while waiting on I/O, so servers handle more concurrent requests. Classic deadlocks came from blocking on async code with .Result or .Wait() in contexts with a synchronisation context; avoid blocking on async code, go async all the way, and use ConfigureAwait(false) in library code. ValueTask avoids allocations when results are often synchronous but has usage restrictions. In dependency injection, transient services are created each time, scoped once per request, and singletons once per application — injecting a scoped service into a singleton is a common bug.
ASP.NET Core
| Topic | Answer |
|---|---|
| Middleware | Components in a pipeline, each able to handle the request or pass it on; order matters |
| Minimal APIs | Concise endpoint definitions, good for small services |
| Controllers | Structured, attribute-routed, convenient for larger APIs and filters |
| Options pattern | Strongly typed configuration bound from appsettings, environment variables or secrets |
| Error handling | Exception-handling middleware returning problem details; structured logging |
Entity Framework Core
- Tracking queries let EF detect changes for updates; AsNoTracking is faster for read-only queries.
- N+1: lazy loading in loops triggers a query per item; use Include for eager loading or project to DTOs with Select.
- Projection — selecting only needed columns into DTOs — often gives the biggest win.
- Migrations generate schema changes from model changes; review generated SQL for large tables.
Performance
For a slow endpoint: measure with tracing and logs, check database queries first (count, plans, indexes, tracking), cache expensive reads, avoid synchronous I/O, reduce allocations in hot paths, use response compression and pagination, and load-test after changes. See C# interview questions and Azure interview questions.
Testing in .NET
Expect questions on unit testing with xUnit or NUnit, mocking dependencies through interfaces, and integration testing ASP.NET Core APIs with an in-memory test server and a real database in a container. Interviewers like candidates who test behaviour through public APIs rather than private methods, and who keep integration tests few but meaningful.
Practising
Reading answers is not the same as saying them. Pick ten of the questions above and answer them aloud against a timer; a free AI interview assistant like CoPilot Interview can ask .NET questions in a mock interview and flag answers that ran long or lacked an example. Prepare one story about a production issue — a deadlock, a memory leak or a slow query — and how you diagnosed it.
Disclosure: CoPilot Interview is our product, so weigh what we say about it accordingly. Everything else on this page applies whichever tool you use, or none.
Frequently asked questions
What are common .NET interview questions?
The CLR and JIT, garbage collection, value versus reference types, IDisposable, async/await and deadlocks, dependency injection lifetimes, ASP.NET Core middleware, configuration, EF Core tracking and N+1 queries, error handling and performance.
What are the DI lifetimes in ASP.NET Core?
Transient creates a new instance every time, scoped creates one per request, and singleton creates one for the application's lifetime.
What causes async deadlocks in .NET?
Blocking on asynchronous code with .Result or .Wait() in a context that needs the blocked thread to resume. Using async all the way avoids it.
When should I use AsNoTracking in EF Core?
For read-only queries, where change tracking adds overhead without benefit.
Practise on real interview questions
Run 145 real interview questions across 10 tracks, answer out loud and see a structured answer to compare with yours. Free, no signup.
Try a practice question