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

πŸ“š .NET Interview Questions

1325 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.

Configuration

appsettings.json, environment-specific settings, user secrets, environment variables, command-line configuration, the options pattern, IOptions, IOptionsSnapshot, IOptionsMonitor and options validation.

  1. Your team has secrets and environment-specific settings scattered across appsettings.json files and portal app settings. How would you move them into Azure Key Vault and Azure App Configuration using managed identity, and how do you handle secret rotation, caching and refresh, start-up failures and feature flags?

    A real-world migration of ASP.NET Core configuration to Azure Key Vault and Azure App Configuration with managed identity: inventory and classification, RBAC roles, AddAzureKeyVault versus App Configuration Key Vault references, labels per environment, sentinel-key refresh and Key Vault reload intervals, rotation with overlapping secret versions, passwordless Entra ID auth, start-up resilience and replicas, feature flags with Microsoft.FeatureManagement, and the rollout plan.

    Senior RealWorldScenario Configuration Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  2. How does configuration work in ASP.NET Core? Explain the default configuration providers and the order they load in (appsettings.json, appsettings.{Environment}.json, user secrets, environment variables, command line), why the last one wins, and how hierarchical keys work with : and __.

    The ASP.NET Core configuration system: IConfiguration as a merged key-value view over ordered providers, the default sources added by WebApplication.CreateBuilder, last-provider-wins precedence, case-insensitive hierarchical keys with colon, double underscore for environment variables, array indexes and reading values with GetValue, GetSection and GetConnectionString.

    Beginner Theory Configuration Β· πŸ”— 2 follow-ups
  3. How do environments work in ASP.NET Core? Explain ASPNETCORE_ENVIRONMENT versus DOTNET_ENVIRONMENT, what IsDevelopment() changes, how environment-specific appsettings files are picked, and what should never go in appsettings.json.

    ASP.NET Core environments: how the environment name is resolved (ASPNETCORE_ENVIRONMENT, DOTNET_ENVIRONMENT, --environment, default Production), IHostEnvironment and IsDevelopment/IsProduction/IsEnvironment, what changes in Development (developer exception page, user secrets, DI validation), appsettings.{Environment}.json selection, launchSettings.json, and what belongs outside appsettings.

    Junior Theory Configuration Β· πŸ”— 2 follow-ups
  4. What are user secrets in .NET? Explain where they are stored, how they get loaded, why they are only for development, why they are not encryption, and what you use instead in production.

    The .NET Secret Manager: UserSecretsId in the project file, dotnet user-secrets init/set/list, the secrets.json location on Windows, Linux and macOS, loading only in the Development environment, why it is plain text outside the repo rather than encryption, and production replacements such as Azure Key Vault with managed identity and platform secret stores.

    Junior Theory Configuration Β· πŸ”— 2 follow-ups
  5. What is the options pattern in ASP.NET Core? Show how you bind a configuration section to a class with Configure<T> or AddOptions<T>().BindConfiguration(), explain how the binder maps keys to properties, and tell me why you shouldn't inject IConfiguration everywhere.

    The options pattern: binding configuration sections to strongly typed classes with Configure<T>, AddOptions<T>().Bind/BindConfiguration, how ConfigurationBinder maps keys to properties (case-insensitive, conversions, collections, missing keys, ErrorOnUnknownConfiguration), IConfigureOptions and PostConfigure for code-based setup, the binding source generator for AOT, and why injecting IConfiguration into services is an anti-pattern.

    Intermediate Theory Configuration Β· πŸ”— 2 follow-ups
  6. What is the difference between IOptions<T>, IOptionsSnapshot<T> and IOptionsMonitor<T>? Explain their lifetimes, how and when each sees configuration changes, how named options work, and which one you would use in a singleton, a controller and a background service.

    IOptions, IOptionsSnapshot and IOptionsMonitor compared: singleton, scoped and singleton lifetimes, computed once versus per scope versus cached and rebuilt on change tokens, CurrentValue and OnChange, named options with Get(name), the captive-dependency error, the per-request rebinding cost of IOptionsSnapshot, and how to choose for singletons, request handlers and BackgroundService.

    Mid-Level Theory Configuration Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  7. Show me how you validate options in ASP.NET Core so the app fails fast on bad configuration. Cover DataAnnotations with ValidateDataAnnotations, ValidateOnStart, custom rules with Validate and IValidateOptions<T>, nested objects, and the source-generated [OptionsValidator].

    Options validation in ASP.NET Core: ValidateDataAnnotations and its reflection cost, Validate delegates, IValidateOptions<T> for cross-property and service-dependent rules, ValidateOnStart to fail at host start-up, ValidateObjectMembers and ValidateEnumeratedItems for nested types, the compile-time [OptionsValidator] source generator for AOT, OptionsValidationException behaviour on reload, and testing validators.

    Mid-Level Coding Configuration Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  8. You set a configuration value in Azure App Service (or a Kubernetes deployment), but the running app still uses the value from appsettings.json. Possible causes include environment variable naming, provider precedence and reloadOnChange with mounted files. How do you diagnose and fix it?

    Diagnosing configuration values that don't take effect in Azure App Service, Container Apps or Kubernetes: environment variable naming (: versus __, ConfigMap key rules, App Service connection string prefixes), provider order and custom sources added last, the wrong environment name, values read once at start-up, mounted ConfigMap symlink swaps and DOTNET_USE_POLLING_FILE_WATCHER, and using GetDebugView with masking, the provider list, printenv and az CLI to find which provider won.

    Mid-Level Debugging Configuration Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  9. Code review: a start-up class stores builder.Configuration in a static AppConfig.Config property, services read keys from it in their constructors (one parses a port with int.Parse and opens a SQL connection), and appsettings.json, committed to git, contains an SMTP password and a live Stripe secret key. What do you find, ranked by severity, and how would you rewrite it?

    Code review of configuration anti-patterns: secrets committed in appsettings.json (incident response, rotation, history, Privacy Act and NDB), constructors that parse configuration and open connections, a static IConfiguration singleton (hidden dependencies, test pollution, no reload), no validation, and the rewrite with options classes, ValidateOnStart, Key Vault with managed identity and passwordless SQL, plus blocking versus suggested review comments and secret scanning.

    Senior CodeReview Configuration Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world

🌐 Sangam's Webring

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