📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

πŸ“š .NET Interview Questions

377 questions for senior .NET engineer interviews, each with a 30-second answer, the full answer, a deep dive, the follow-ups interviewers ask next, and real-world production problems.

Phase 1 — Computer Science Fundamentals

How computers, operating systems, file systems and networks really work, plus the core data structures and algorithms, explained for .NET 10 engineers.

  1. What is memory alignment and padding? How does the CLR lay out structs and classes in memory, and when would you control layout with StructLayout?

    Natural alignment, padding and why misaligned access is slow or non-atomic, how the CLR lays out classes (auto) and structs (sequential by default, auto when they contain references), object headers and minimum object size, measuring sizes, and using StructLayout, FieldOffset, Pack and InlineArray for interop and performance.

    Senior Theory Memory Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  2. A .NET service suddenly crashes with a StackOverflowException. Why can't you catch it, and how do you find and fix the cause?

    How the call stack overflows, why .NET terminates the process instead of letting you catch it, common causes (unbounded or deep recursion, self-referencing properties, cyclic object graphs, large stackalloc), and how to diagnose with crash output, dumps and tests.

    Mid-Level Debugging Memory Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  3. Your .NET service in Kubernetes keeps getting OOMKilled even though the GC heap looks small. How do RAM, virtual memory, working set, private bytes and the GC heap relate, and how do you investigate?

    Process memory from the operating system's and the runtime's point of view: physical RAM versus virtual address space, working set, private and committed memory, the GC heap and native memory, container cgroup limits, GC heap hard limits, Server GC and DATAS, and a step-by-step investigation of OOMKilled pods.

    Senior RealWorldScenario Memory Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  4. How does the .NET managed heap allocate objects? Explain allocation contexts, generations, the large object heap and the pinned object heap.

    How allocation works on the managed heap (bump-pointer allocation in per-thread contexts), how generations and promotion keep collections cheap, when objects go to the large object heap, why pinning matters and the pinned object heap, and how to measure and reduce allocations.

    Mid-Level Theory Memory Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  5. What is the operating system kernel, and what is the difference between user mode and kernel mode?

    The kernel's responsibilities, CPU privilege levels (rings on x64, exception levels on Arm64), why applications run in user mode, how and when the CPU switches to kernel mode, and what that means for .NET applications, drivers, containers and security.

    Junior Theory Operating System Β· πŸ”— 2 follow-ups
  6. What is a system call? How does a .NET call like File.ReadAllBytesAsync or Socket.SendAsync reach the kernel, and why can system calls be expensive?

    The system call mechanism, the path from .NET APIs through SafeHandles and the PAL to Windows (IOCP) and Linux (epoll) interfaces, the cost of crossing into the kernel, and how buffering, batching and async I/O reduce that cost. Includes tracing system calls with strace and Process Monitor.

    Mid-Level Theory Operating System Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  7. What is the difference between a process and a thread? How do they map to .NET concepts such as Process, Thread, the thread pool and Task?

    What a process owns (address space, handles, security context) versus what a thread owns (stack, registers, thread-local storage), how threads share memory, how .NET threads map to OS threads, how the thread pool and Task build on them, and when to use multiple processes instead of threads.

    Junior Theory Operating System Β· πŸ”— 3 follow-ups
  8. How does the operating system scheduler decide which thread runs next, and what do preemption, time slices, priorities and container CPU limits mean for a .NET service?

    Preemptive scheduling, run queues, time slices, priorities and starvation, how Windows and Linux schedulers differ at a high level, CPU affinity and NUMA, and how cgroup CPU quotas throttle containers and interact with the .NET thread pool and GC.

    Mid-Level Theory Operating System Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  9. What is a context switch, what does it cost, and why can having too many threads make a .NET service slower?

    What the OS saves and restores on a context switch, thread versus process switches, direct and indirect costs (cache and TLB pollution), voluntary versus involuntary switches, how blocking code and oversized thread counts multiply them, and how to measure and reduce them.

    Mid-Level Theory Operating System Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  10. Explain virtual memory and paging. How does the operating system map a process's virtual addresses to physical RAM?

    Why virtual memory exists, pages and page frames, multi-level page tables, the TLB, demand paging, copy-on-write, memory-mapped files, swap and the page file, overcommit, address space layout randomisation, and what all this means for .NET processes.

    Mid-Level Theory Operating System Β· πŸ”— 2 follow-ups
  11. What is a page fault? Explain soft (minor) vs hard (major) page faults, and how you would investigate a .NET service whose latency spikes line up with a high page fault rate.

    Page faults, minor vs major faults, what triggers them, and how to diagnose paging-related latency in a .NET service.

    Senior Debugging Operating System Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  12. What are file descriptors on Linux and handles on Windows? How does .NET manage them, and why does SafeHandle exist?

    File descriptors and handles as the OS's per-process references to kernel resources, their limits, and how .NET wraps them with SafeHandle and IDisposable.

    Mid-Level Theory Operating System Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  13. A .NET service on Linux starts failing with "Too many open files" and SocketException errors under load. Walk me through how you would diagnose it, including HttpClient socket exhaustion and TIME_WAIT.

    Diagnosing descriptor exhaustion and socket exhaustion in .NET on Linux: ulimit, lsof, ss, TIME_WAIT, ephemeral ports, and the HttpClient/IHttpClientFactory fixes.

    Senior Debugging Operating System Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  14. What actually is a file and a directory at the operating system level, and how do you list and walk directories efficiently in .NET?

    Files, directories, metadata, inodes and links, plus efficient directory enumeration in .NET with EnumerateFiles and EnumerationOptions.

    Junior Theory File System Β· πŸ”— 3 follow-ups
  15. How do you build and handle file paths so that a .NET application works on both Windows and Linux? Explain absolute vs relative paths, separators, Path.Combine vs Path.Join, and case sensitivity.

    Cross-platform path handling in .NET: separators, absolute vs relative paths, the current directory, Path.Combine vs Path.Join, case sensitivity and long paths.

    Intermediate Theory File System Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  16. Code review: this endpoint returns a file from the server based on a name in the query string. What is wrong with it, and how would you fix it? ```csharp app.MapGet("/download", (string file) => { var path = Path.Combine("/var/app/reports", file); return Results.File(path, "application/octet-stream"); }); ```

    Path traversal (directory traversal) in a file download endpoint, why Path.Combine does not protect you, and safe patterns including root checks, ID mapping and Zip Slip.

    Senior CodeReview File System Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  17. How do file permissions work on Linux and Windows? Your .NET app works locally but throws UnauthorizedAccessException when writing to a mounted folder in a container. How do you fix it properly?

    Unix permission bits, owners and groups, Windows ACLs, how .NET exposes them, and fixing permission errors for non-root containers with mounted volumes.

    Mid-Level Debugging File System Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  18. What is a Stream in .NET? Explain how FileStream, MemoryStream and wrapper streams like GZipStream fit together, and the common mistakes when reading from a stream.

    The Stream abstraction, backing vs decorator streams, Read semantics, Position and CanSeek, disposal chains, async I/O and when to use StreamReader or Pipelines.

    Mid-Level Theory File System Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  19. Explain the layers of buffering between your .NET code and the disk. What does Flush actually guarantee, and how do you write a file so it survives a crash or power loss?

    Application, FileStream, OS page cache and device buffers; Flush vs Flush(true)/fsync; WriteThrough; atomic write-then-rename; ArrayPool for I/O buffers.

    Senior Theory File System Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  20. "The process cannot access the file because it is being used by another process." How do file locks work on Windows and Linux, how does FileShare affect them, and how do you debug and fix this error?

    Share modes, mandatory vs advisory locking, byte-range locks, how .NET maps FileShare on each OS, finding the process holding a file, and safe cross-process coordination.

    Mid-Level Debugging File System Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world

🌐 Sangam's Webring

βͺ Previous 🏠 Main Next ⏩
πŸ’¬ Chat with me