.NET interview questions

36 questions, easy to hard. Read one, then answer it out loud: an AI interviewer follows up, hints when you're stuck and grades your answer.

.NET interviews go past C# syntax: how async and memory work, how ASP.NET Core handles a request, and how you'd run and operate the service on AWS, from Lambda and containers to data and monitoring.

C# and .NET Fundamentals

  1. In C#, you change a property on a copy of a struct and the original stays the same, but you do the same with a copy of a class instance and the original changes too. Explain the difference between value types and reference types, and when you'd choose a struct.

    What a strong answer covers
    • What gets copied on assignment for each kind of type.
    • Why the two examples behave differently.
    • Where values really live in memory, beyond the usual simplification.
    • What makes data a good fit for a struct, and a hidden cost to watch for.

    Common mistake: Saying structs always live on the stack and classes on the heap, as if that rule were the defining difference.

  2. An ASP.NET Core endpoint reads from a database and then calls another web service. A colleague asks why the code uses async and await at all, and whether it would be simpler to call dot Result on the tasks. Explain what await actually does and why blocking on a task is a bad idea.

    What a strong answer covers
    • What a task stands for and what happens at an await.
    • Why freeing threads matters for a busy web server.
    • The risks of blocking on unfinished work.
    • Habits that keep async code healthy across a whole codebase.

    Common mistake: Thinking await starts a new thread to run the work, when for input and output there's usually no thread busy at all while it waits.

  3. Your team is turning on nullable reference types in an older C# project and gets hundreds of warnings. Explain what the feature does, what it does and doesn't guarantee at run time, and how you'd roll it out without just silencing everything.

    What a strong answer covers
    • What the annotations express and what the compiler does with them.
    • Where the guarantees stop and nulls can still sneak in.
    • The temptation to silence warnings, and why it backfires.
    • A realistic way to adopt it in a large existing codebase.

    Common mistake: Believing a non-nullable property can never hold null at run time, so skipping validation of incoming data.

  4. A method builds a LINQ query with Where and Select over an Entity Framework table, then calls Count on it and loops over it. The logs show the database being queried twice. Explain deferred execution, why this happens, and the difference between IEnumerable and IQueryable here.

    What a strong answer covers
    • When a LINQ query actually does its work.
    • Why the database was hit twice and how to avoid it.
    • How the two interfaces decide where filtering runs.
    • The performance trap of leaving the database too early.

    Common mistake: Calling ToList straight after the table and filtering afterwards, which quietly loads the whole table into memory.

  5. In an ASP.NET Core app, a service registered as a singleton takes an Entity Framework DbContext in its constructor, and under load you see strange errors about the context being used by two threads at once. Explain the three service lifetimes, what's gone wrong, and how to fix it.

    What a strong answer covers
    • What each lifetime means in a web app.
    • How a long-lived service can trap a short-lived one.
    • Ways to restructure so each request gets its own context.
    • The built-in safety net that can catch this before production.

    Common mistake: Fixing the errors by adding locks around the shared context instead of fixing the lifetimes.

  6. A .NET service running in a container slowly grows its memory until the container is killed. Explain how the .NET garbage collector works, how a garbage-collected app can still leak memory, and how you'd investigate this one.

    What a strong answer covers
    • How the collector organises objects by age and why.
    • The special treatment of large allocations.
    • What a leak means when memory is managed for you.
    • A practical way to find what's holding on to memory.

    Common mistake: Calling GC dot Collect or adding Dispose everywhere, when the real problem is something still holding references.

ASP.NET Core Web APIs

  1. A new developer moved the line that adds authorisation above the line that adds authentication in an ASP.NET Core app, and now every protected endpoint returns an error. Explain how the middleware pipeline works and why the order matters.

    What a strong answer covers
    • How a request and its response travel through the pipeline.
    • How a component can end the request early.
    • Why identifying the user has to come before checking permissions.
    • Other places where order changes behaviour.

    Common mistake: Treating the registration calls as a list of independent settings, when they build a chain that runs in exactly that order.

  2. Your team is starting a new ASP.NET Core service and can't agree whether to use minimal APIs or controllers. Explain the difference between them and how you'd decide.

    What a strong answer covers
    • How each style maps a request to your code.
    • What both have in common underneath.
    • Situations that favour the lighter style.
    • Situations that favour the class-based style, and how the lighter one scales up.

    Common mistake: Assuming minimal APIs are only for demos and can't handle authentication, validation or a large codebase.

  3. An ASP.NET Core service reads settings from appsettings files, but in production on AWS the values need to come from somewhere else, and the code reads them with string keys scattered everywhere. Explain how .NET configuration is layered, how to override values per environment, and how the options pattern tidies it up.

    What a strong answer covers
    • How settings from different sources are merged.
    • How production values replace development ones safely.
    • Moving from string lookups to typed, validated settings.
    • Choosing how and when the app sees changed values.

    Common mistake: Committing production passwords to appsettings files because that's where the other settings live.

  4. A .NET service creates a new HttpClient inside a using block for every outgoing call, and under load it starts failing with socket errors. A colleague suggests one static HttpClient instead. Explain what's going wrong and the best way to make outgoing HTTP calls.

    What a strong answer covers
    • Why short-lived clients exhaust resources.
    • The hidden downside of a single client that never changes.
    • The framework's answer that balances both problems.
    • Protecting the caller when the other service misbehaves.

    Common mistake: Wrapping HttpClient in a using block because it implements IDisposable, as you would a file.

  5. Your ASP.NET Core API on AWS must accept access tokens issued by an Amazon Cognito user pool, and some endpoints should be open only to admins. Explain how you'd configure authentication and authorisation, and what the API must check on each token.

    What a strong answer covers
    • How the API learns to trust tokens from the identity provider.
    • What makes a token valid for this particular API.
    • Keeping identity and permissions as separate steps.
    • Which error the caller gets in each failure case.

    Common mistake: Decoding the token and reading its claims without validating the signature, so anyone can forge an admin token.

  6. An ASP.NET Core API sends welcome emails by starting a fire-and-forget Task dot Run inside the request handler, and some emails are never sent, especially during deploys. Explain why, and how you'd do background work properly in .NET, both inside the app and when it really matters that the work happens.

    What a strong answer covers
    • Why untracked work disappears.
    • The framework's way to run long-lived work inside the app.
    • Lifetime and error-handling traps inside background services.
    • When to move work out of the process to something durable.

    Common mistake: Swapping Task dot Run for an in-memory queue and assuming emails can no longer be lost.

.NET on AWS Lambda

  1. A teammate's .NET Lambda function creates a new DynamoDB client and HttpClient inside the handler on every call, and stores the current user's id in a static field. Explain how Lambda runs a .NET function, from the first request to later ones, and what you'd change in this code.

    What a strong answer covers
    • The phases a function goes through and which code runs in each.
    • How Lambda handles more traffic.
    • What's worth setting up once and reusing.
    • Why shared state across invocations is risky.

    Common mistake: Assuming every invocation starts from a clean process, so static state is harmless and setup cost doesn't matter.

  2. A .NET Lambda function runs with the smallest memory setting to save money, yet each call takes several seconds. Explain how Lambda pricing and memory work, and how you'd find the right setting.

    What a strong answer covers
    • What you're billed for on each call.
    • The link between the memory setting and processing power.
    • Why a bigger setting can be cheaper.
    • How to find the sweet spot with evidence, and another lever on price.

    Common mistake: Picking the lowest memory setting for a CPU-heavy .NET function because it looks cheapest per millisecond.

  3. Users of a .NET API on Lambda complain that the first request after a quiet spell takes two or three seconds, while later ones are fast. Explain what a cold start is, why .NET functions can feel it more than some runtimes, and the options for reducing it.

    What a strong answer covers
    • What happens during a cold start and when it occurs.
    • Why .NET in particular pays for startup.
    • Changes to code and build that shorten startup.
    • Platform features that hide startup, with their costs.

    Common mistake: Scheduling a ping every few minutes to keep one environment warm, which does nothing for the extra environments created when traffic rises.

  4. You want to move an existing ASP.NET Core web API from a virtual machine to Lambda behind Amazon API Gateway with as few code changes as possible. Explain how that works, the limits you'd check first, and whether to keep one function for the whole API or split it up.

    What a strong answer covers
    • How an existing web app can run inside a function.
    • Choosing between the two kinds of API Gateway.
    • Platform limits worth checking before moving.
    • The trade-off between one big function and many small ones.

    Common mistake: Moving the API without checking request duration and payload size, then finding report downloads and long exports fail.

  5. A .NET Lambda function processes orders from an Amazon SQS queue in batches of ten. When one bad message fails, all ten get processed again, some orders are charged twice, and the bad message keeps coming back. Explain how Lambda reads from SQS and how you'd fix each problem.

    What a strong answer covers
    • How the queue and the function work together, including retries.
    • Avoiding repeat work for messages that already succeeded.
    • Parking messages that will never succeed, and tuning timeouts.
    • Making repeated deliveries harmless.

    Common mistake: Catching every exception and returning success so the batch is never retried, which silently drops the failed orders.

  6. Your team wants to compile a .NET Lambda function with Native AOT to cut its cold starts. Explain what Native AOT does, what has to change in the code and build, and when it isn't worth it.

    What a strong answer covers
    • What ahead-of-time compilation changes about startup.
    • How such a function is built and deployed.
    • The coding rules that come with it.
    • Cases where the effort isn't repaid, and lighter alternatives.

    Common mistake: Ignoring trim warnings because the build succeeds, then hitting missing-type errors at run time in production.

Data on AWS from .NET

  1. In an ASP.NET Core service, a developer creates a new Amazon S3 client inside every method, hard-codes the region, and can't unit test the class that uses it. Explain how you'd set up and use AWS SDK clients in a .NET app.

    What a strong answer covers
    • How clients should be created and shared.
    • Why sharing them is safe and cheaper.
    • Keeping environment-specific settings out of the code.
    • Making code that talks to AWS testable.

    Common mistake: Wrapping each SDK client in a using block per request, as if it were a database connection.

  2. Your .NET app stores customers' invoices in Amazon S3, and a colleague proposes making the bucket public so the website can link to the files. Explain why not, and how you'd store and share the invoices safely.

    What a strong answer covers
    • Why public access is the wrong default for customer files.
    • How the application gets just enough access.
    • Ways to hand one person one file for a short time.
    • Further layers of protection for stored data.

    Common mistake: Relying on long random file names to keep a public bucket safe.

  3. A .NET endpoint lists a customer's orders from DynamoDB. It uses a Query with a filter on status and a limit of 20, but some pages come back with only three orders, or none, even though there are more. Explain how DynamoDB pagination works and how you'd fix the endpoint.

    What a strong answer covers
    • How DynamoDB splits results across calls.
    • Why filtered pages can come back short.
    • The cost side of filtering, and a better design.
    • How an API should page through results for its clients.

    Common mistake: Treating an empty or short page as the end of the results without checking for a key to continue from.

  4. A .NET endpoint on Aurora PostgreSQL returns a list of orders with their lines and payments using Entity Framework Core, and it has become slow and memory-hungry. Explain what Entity Framework might be doing behind the scenes and the changes you'd try.

    What a strong answer covers
    • Seeing what the ORM really sends before guessing.
    • The hidden cost of loading entities for editing when you only read them.
    • How eager and lazy loading can each go wrong.
    • Shaping queries to fetch only what the page needs.

    Common mistake: Blaming the database and scaling up the instance before looking at the queries the ORM generates.

  5. A .NET Lambda function behind an API connects to an Aurora PostgreSQL database. During a traffic spike the database refuses new connections and the API fails, though the database CPU is low. Explain why, and how you'd fix it.

    What a strong answer covers
    • How Lambda's scaling model meets a database's connection limit.
    • A managed service built for this problem.
    • Putting a ceiling on how hard the function can push the database.
    • Other ways to talk to the database or reduce load.

    Common mistake: Raising the database's maximum connections, which only moves the limit and spends memory on idle connections.

  6. Two instances of a .NET service read the same stock record from DynamoDB, each subtracts one and writes it back, and the shop oversells. Separately, a retried request creates a duplicate order. Explain how to use DynamoDB's conditional writes and transactions to prevent both.

    What a strong answer covers
    • Why read-modify-write loses updates under concurrency.
    • Making a write depend on the current state of the item.
    • Turning a retried request into a no-op.
    • Grouping writes that must succeed or fail together.

    Common mistake: Adding a lock inside the .NET service, which does nothing when several instances write to the same table.

Containers and Deployment

  1. Your team is moving an ASP.NET Core API to AWS and must choose between AWS Lambda and Amazon ECS on Fargate. Explain how the two differ and which you'd pick for a quiet internal tool and for a busy public API with WebSocket connections.

    What a strong answer covers
    • How each service runs your code and charges for it.
    • The constraints that matter for a web API.
    • Matching each workload to the better fit, with reasons.

    Common mistake: Choosing Lambda for everything because it's serverless, without checking traffic shape or connection needs.

  2. You need a container image for an ASP.NET Core 8 API to run on AWS. Explain how you'd build a small, secure image, and what's different about recent .NET images compared with older guides you might find.

    What a strong answer covers
    • Separating the build environment from what runs in production.
    • Ordering steps so rebuilds are fast.
    • Defaults in current .NET images that older advice predates.
    • Ways to shrink the image further or build and publish it.

    Common mistake: Shipping the full SDK image to production, which makes it several times bigger and gives an attacker compilers to use.

  3. You're deploying a containerised ASP.NET Core API to Amazon ECS on Fargate behind an Application Load Balancer. Explain the main pieces you'd set up, how the app gets its secrets and AWS permissions, and how it scales.

    What a strong answer covers
    • The resources that describe and run the app.
    • The two kinds of permission and who uses each.
    • Getting configuration and secrets in safely, and checking health.
    • Growing and shrinking with load, and surviving a zone outage.

    Common mistake: Giving one broad role to both ECS and the application, so the app ends up with far more access than it needs.

  4. Your .NET team wants to define its AWS infrastructure in C# with the AWS Cloud Development Kit instead of clicking in the console. Explain how the CDK works, what constructs are, and how you'd use it safely.

    What a strong answer covers
    • How C# code turns into deployed resources.
    • The layers of building blocks and when to use each.
    • How the CDK helps keep permissions tight.
    • A safe day-to-day workflow, and a setup surprise for .NET teams.

    Common mistake: Hand-writing broad IAM policies with wildcards in CDK code instead of using the grant methods.

  5. Every deploy of your .NET Lambda function replaces the code for all traffic at once, and last week a bad release broke checkout for everyone. Explain how Lambda versions and aliases work and how you'd roll out new code gradually with automatic rollback.

    What a strong answer covers
    • The difference between immutable versions and the moving latest code.
    • Using named pointers so callers never change.
    • Shifting traffic in steps rather than all at once.
    • Letting monitoring decide whether to continue or undo.

    Common mistake: Wiring API Gateway or other callers to the latest unpublished version, so every deploy goes straight to all users.

  6. During ECS rolling deploys of your ASP.NET Core service, users see errors for a minute or two, and once a release that crashed on startup kept being retried for an hour. Explain how ECS rolling deployments work and how you'd make them safe.

    What a strong answer covers
    • How the rolling settings keep capacity during a deploy.
    • How readiness is judged before traffic arrives.
    • Stopping and reversing a deployment that's failing.
    • Letting old tasks finish their work before they go.

    Common mistake: Pointing the health check at a page that always returns success, so tasks that can't reach the database still get traffic.

Running .NET on AWS in Production

  1. A .NET service reads an AWS access key and secret key from its appsettings file to call S3 and DynamoDB. Explain why that's risky and how the app should get AWS credentials when it runs on Lambda or ECS, and on a developer's laptop.

    What a strong answer covers
    • Why stored long-term keys are dangerous.
    • How the SDK finds credentials without being told.
    • Where credentials come from when the app runs on AWS.
    • Keeping access narrow, and a safe setup for local development.

    Common mistake: Moving the keys into environment variables and calling it fixed, when they're still long-lived keys.

  2. Your .NET service needs a database password, a third-party API key and a dozen ordinary settings such as feature limits. Explain the difference between AWS Secrets Manager and Systems Manager Parameter Store, which you'd use for each, and how the app should read them.

    What a strong answer covers
    • What each service is designed for and how it's priced.
    • Matching each kind of value to a service.
    • Getting the values into the app efficiently and securely.

    Common mistake: Calling the secrets service on every request, which adds latency, cost and the risk of being throttled.

  3. A customer reports a failed payment in your .NET service on AWS, and the CloudWatch logs are millions of lines of plain text built with string interpolation. Explain how you'd change the logging so you can find that request quickly next time, and how you'd search for it.

    What a strong answer covers
    • Logging values as data rather than text.
    • A format the log service can query.
    • Linking every line of one request together.
    • Searching quickly, and keeping log volume and cost in check.

    Common mistake: Logging everything at debug level in production to be safe, then struggling with the bill and the noise.

  4. A request passes through API Gateway, an ASP.NET Core service on ECS, a .NET Lambda function and DynamoDB, and sometimes takes five seconds. Explain how distributed tracing would show you where the time goes, and how you'd set it up for .NET on AWS today.

    What a strong answer covers
    • What a trace and its parts show.
    • How services stitch their work into one trace.
    • The current tooling choice for .NET on AWS.
    • Keeping volume affordable and tying traces to logs.

    Common mistake: Instrumenting each service separately without propagating context, which gives disconnected fragments instead of one trace.

  5. Your team gets dozens of CloudWatch alarms a day about CPU and memory on a .NET service, ignores them, and missed a real outage last week. Explain which alarms you'd keep for a service made of an API on ECS, Lambda functions and an SQS queue, and how you'd make them trustworthy.

    What a strong answer covers
    • Alerting on what customers experience.
    • The telling signals for queues and functions.
    • Statistics and settings that reduce noise.
    • Making every alert actionable, and pruning the rest.

    Common mistake: Alarming on average latency, which hides the slow requests a minority of users are suffering.

  6. Finance asks you to cut the monthly AWS bill of a .NET platform: several ECS Fargate services, some Lambda functions, private subnets with NAT gateways, and lots of CloudWatch logs. Explain how you'd find where the money goes and the changes you'd consider, with their trade-offs.

    What a strong answer covers
    • Finding the biggest costs before acting.
    • Paying for the compute you actually use.
    • Hidden network charges and how to avoid them.
    • Pricing models and housekeeping that trade commitment or risk for savings.

    Common mistake: Cutting task sizes across the board without checking usage, then causing out-of-memory crashes at peak.

Questions about practising

How should I prepare for .NET interview questions?
Practise answering them out loud, not just reading them. Explaining an answer under follow-up questions is what interviews test. Work through the 36 questions here from easy to hard, and revisit the ones you struggle with.
Can I practise .NET interview questions with an AI?
Yes. Open any question and start a voice session: an AI interviewer asks it, follows up on your answer, gives hints when you're stuck and grades your answer with written feedback when the call ends.
Are these .NET interview questions free?
5 of the 36 questions are free to practise. Sign in with Google, no card needed. Pro unlocks the rest, plus practice calls to your phone.