Role preparation

.NET Developer interview questions and answers.

ASP.NET Core middleware order, authentication, cancellation, dependency injection, and EF Core data access.

Questions

Technical questions to practise out loud

  1. 01

    How can async/await cause deadlocks in .NET?

    A deadlock can occur when code blocks on Task.Result or Wait while the continuation needs the captured synchronization context. Keep the call chain async, await tasks, avoid sync-over-async, and do not hold locks across await.

    Read the full breakdown
  2. 02

    How do .NET dependency injection lifetimes differ?

    Transient creates each resolution, scoped reuses one instance per request or scope, and singleton lives for the application. A singleton must not capture scoped services and shared state must be thread-safe.

    Read the full breakdown
  3. 03

    How does Entity Framework change tracking work?

    EF Core tracks entity identity, original values, and state in a DbContext, then generates updates on SaveChanges. Use short-lived contexts and AsNoTracking for read-only queries to reduce memory and surprises.

    Read the full breakdown
  4. 04

    How does garbage collection work in .NET?

    .NET GC allocates managed objects in generations, traces reachable objects from roots, compacts eligible heaps, and treats large objects separately. Allocation rate, retention, finalizers and pauses should be measured before tuning.

    Read the full breakdown
  5. 05

    How do you order ASP.NET Core middleware?

    ASP.NET Core middleware wraps the next component, so order defines both request and reverse response flow. Put exception handling early, routing before endpoint-dependent policies, authentication before authorization, and endpoints last.

    Read the full breakdown
  6. 06

    How do you propagate cancellation in .NET?

    Accept CancellationToken at public async boundaries and pass it to every cancellable I/O call. Stop promptly without converting cancellation into a server error, and never replace a request token with CancellationToken.None.

    Read the full breakdown
  7. 07

    How do you manage configuration in .NET?

    Layer .NET configuration from checked-in defaults, environment-specific providers, and an external secret store; bind validated options, fail fast on missing required values, and avoid environment branches scattered through business code.

    Read the full breakdown
  8. 08

    What is your .NET testing strategy?

    Use unit tests for domain logic, WebApplicationFactory tests for the HTTP pipeline, integration tests with real data stores for EF queries, and focused end-to-end tests; control clocks, cancellation, and external clients.

    Read the full breakdown
  9. 09

    How do you secure an ASP.NET Core API?

    Secure ASP.NET Core with validated authentication, policy or resource-based authorization, HTTPS, protected secrets and keys, antiforgery for cookie flows, input validation, safe data access, rate limits, and patched dependencies.

    Read the full breakdown
  10. 10

    How do you diagnose a slow .NET service?

    Correlate .NET latency and throughput metrics with traces, inspect thread-pool starvation, GC and allocations using dotnet-counters or traces, profile hot paths, check database calls, then benchmark the measured fix.

    Read the full breakdown