title: Senior .NET Interview Questions: 20 Questions and What a Good Answer Covers slug: senior-dotnet-interview-questions topic: career tags: Career, Interview, C#, ASP.NET Core excerpt: 20 questions senior C# and ASP.NET Core interviews actually ask, from async and memory to EF Core, security and design, with what a strong answer covers. cover: Senior .NET
Senior .NET interviews rarely ask you to recite syntax. They ask why: why this lifetime, why this query is slow, why you would or wouldn't split a service. The questions below come up again and again for senior C# and ASP.NET Core roles. For each, you get the points a strong answer covers. Use them to find the gaps in your own answers, not as a script to memorise. Answers reflect .NET 10, C# 14 and EF Core 10.
C# and the runtime
1. What actually happens when you await a task?
The method is compiled into a state machine. At an await on an incomplete task, the method returns to its caller and registers a continuation. When the task completes, the continuation resumes the method, on the captured SynchronizationContext if there is one. ASP.NET Core has none, which is why ConfigureAwait(false) matters for libraries but rarely for application code. A strong answer mentions that async doesn't create threads.
2. When would you use ValueTask instead of Task?
When a method usually completes synchronously, such as a cache hit, and is called often enough that the Task allocation shows up in profiles. The cost: a ValueTask must be awaited exactly once and never awaited concurrently. Default to Task; switch with a benchmark to back you.
3. What is the difference between a class, a struct and a record?
Classes are reference types with reference equality. Structs are value types, copied on assignment, best when small and immutable. Records add value-based equality, with expressions and a readable ToString; record struct gives you the same on a value type. Good answers mention the copy cost of large structs and the boxing that happens when a struct is used through an interface.
4. How does the garbage collector decide what to collect?
Generational: most objects die young, so gen 0 is collected often and cheaply; survivors are promoted. Objects of 85,000 bytes or more go on the Large Object Heap, collected with gen 2. Senior answers connect this to practice: avoid allocations in hot paths with Span<T> and ArrayPool<T>, and measure with dotnet-counters before tuning.
5. What does IDisposable guarantee, and what doesn't it?
It guarantees nothing by itself: it is a contract that callers must honour with using. Finalizers are a safety net for unmanaged resources, not a replacement. Mention IAsyncDisposable for resources that flush asynchronously, such as streams and database connections.
ASP.NET Core
6. Explain the three service lifetimes and a bug each one can cause.
Singleton: one instance for the app; capturing a scoped service inside it (a captive dependency) keeps a DbContext alive forever. Scoped: one per request; resolving it from the root provider in a background service fails or leaks. Transient: new every time; a transient HttpClient exhausts sockets. Strong answers mention ValidateScopes and IHttpClientFactory.
7. Why does middleware order matter?
Each middleware wraps the next. Authentication must run before authorization, exception handling must be first to catch everything, and static files usually come before routing so they skip the rest of the pipeline. Give a real example of a bug caused by the wrong order.
8. Minimal APIs or controllers?
Both run on the same routing and are equally fast in practice. Minimal APIs suit small, focused services and vertical slices; controllers suit large APIs that benefit from filters, conventions and model binding attributes in one place. The senior answer is "it depends on the team and the codebase", followed by what it depends on.
9. How would you run work in the background in ASP.NET Core?
BackgroundService with PeriodicTimer for in-process work; a Channel<T> to hand work from requests to a background worker; a durable queue or job library (Hangfire, Quartz, a message broker) when work must survive a restart. Mention graceful shutdown: honour the stoppingToken.
10. How do you make an API idempotent?
GET, PUT and DELETE should already be; POST is the problem. Accept an Idempotency-Key header, store the key with the result, and return the stored result for a repeated key. Use a unique index so two concurrent requests can't both win.
Data and EF Core
11. A page is slow and EF Core is involved. What do you check first?
Log the generated SQL. Look for N+1 queries (lazy loading or a query in a loop), loading whole entities to show three columns (use Select), tracking queries for read-only pages (use AsNoTracking), and missing indexes in the execution plan. Measure before and after.
12. How does EF Core handle concurrent updates to the same row?
By default, last write wins. Add a concurrency token (rowversion in SQL Server) and EF Core includes it in the WHERE clause; a conflict throws DbUpdateConcurrencyException, which you resolve by reloading, merging or asking the user.
13. When would you not use EF Core?
Bulk operations over many rows (use ExecuteUpdate/ExecuteDelete or bulk copy), heavy reporting queries that are clearer in SQL, and hot paths where Dapper's lower overhead shows up in measurements. Strong answers say they mix both in one app without guilt.
14. Explain transaction isolation levels in one minute.
Read committed (SQL Server's default) avoids dirty reads but allows non-repeatable reads. Repeatable read and serializable hold more locks for stronger guarantees. Snapshot isolation gives readers a consistent view without blocking writers, at the cost of tempdb version storage.
Security
15. Walk me through JWT authentication and its weak points.
The server signs a token with claims; the client sends it; the server validates signature, issuer, audience and lifetime. Weak points: tokens can't be revoked before expiry (keep them short-lived and use refresh tokens), secrets committed to source control, and accepting tokens without validating the audience.
16. How do you protect an ASP.NET Core app against the OWASP top risks?
Parameterised queries (EF Core does this), output encoding (Razor does this), anti-forgery tokens on cookie-authenticated forms, authorization on every endpoint by default with a fallback policy, security headers including a Content Security Policy, rate limiting on sign-in, and keeping packages patched with dotnet list package --vulnerable.
Design and production
17. Monolith or microservices for a new product?
A well-structured monolith first, almost always. Microservices buy independent deployment and scaling at the cost of network calls, distributed data and operational load. Split when a team or a scaling need demands it, along boundaries the monolith has already proven.
18. How do you know your service is healthy in production?
Structured logs with a correlation ID, metrics (request rate, error rate, latency percentiles), traces across service calls with OpenTelemetry, health checks for the load balancer, and alerts on symptoms users feel, not on CPU alone.
19. Tell me about a production incident you handled.
This one is about you. A strong answer follows a shape: what users saw, how you found the cause, the fix, and what you changed so it can't happen again. Interviewers listen for ownership and calm, not heroics.
20. How do you review a junior developer's pull request?
Correctness and security first, then design, then style, which a formatter should handle. Ask questions instead of giving orders, explain the why, approve when it is good enough rather than perfect, and pair when the comments get long.
How to prepare
Answer each question out loud in two minutes, then again with an example from your own work. The example is what separates a senior answer from a textbook one. If you can't think of one for a question, that is the topic to build something small around this week.