What is App.config in C.NET? How to use it?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
App.config is the XML configuration file traditionally used by .NET Framework desktop, console, and service applications. It lets you keep settings outside compiled code so values such as connection strings, API endpoints, and feature flags can change without editing source. The key idea is simple: code reads configuration, but configuration itself lives in a deployable file.
What App.config Actually Does
An App.config file is included in the project and transformed into an output file when you build. For a console app, the built output is typically named something like MyApp.exe.config.
That output file travels with the executable and contains structured XML sections. Common sections include:
- '
appSettingsfor key-value pairs' - '
connectionStringsfor database connections' - runtime sections for assembly binding or other framework behavior
Here is a minimal example:
The file is meant for configuration, not for logic. That separation makes deployment and environment changes easier to manage.
Read Settings From C#
In classic .NET Framework projects, ConfigurationManager is the normal API for reading App.config values.
For connection strings:
In SDK-style projects targeting newer .NET, you may need the System.Configuration.ConfigurationManager package if you still want to use this configuration style.
When App.config Is a Good Fit
App.config works well for settings that differ by environment or deployment but are not supposed to be hard-coded. Typical examples are:
- file paths
- API base URLs
- log levels
- connection strings
- timeout values
This is especially useful in older Windows desktop or service applications where App.config is the conventional configuration mechanism.
Update Settings Without Recompiling
One of the main benefits is operational flexibility. If a test environment uses a different database or service URL, the deployed .config file can be changed without rebuilding the executable.
That does not mean every setting should be editable by hand, but it is often better than recompiling an app just to change a server name.
Keep Secrets Out of Plain Text When Possible
A frequent misuse of App.config is storing passwords or API secrets in plain text. Technically it works, but it is weak operational practice.
Safer options include:
- Windows-integrated authentication
- environment-specific secret stores
- encryption of protected configuration sections
If a value is sensitive, treat App.config as a distribution convenience, not as a secure vault.
App.config Versus Modern .NET Configuration
In newer .NET applications, especially ASP.NET Core and modern worker services, appsettings.json and the generic host configuration stack are more common. That does not make App.config useless. It just means App.config belongs mostly to traditional .NET Framework-style application models.
So a practical rule is:
- use
App.configin classic .NET Framework app types that already expect it - use the newer configuration system in modern .NET applications
Knowing that distinction prevents confusion when switching between older and newer .NET codebases.
Common Pitfalls
The biggest mistake is assuming App.config is automatically the same file name in the build output; the deployed file is usually renamed to match the executable. Another is hard-coding configuration values in code and then adding App.config later only partially, which defeats the purpose of centralized settings. Developers also put secrets into plain text configuration files without thinking about deployment security. Finally, teams moving between .NET Framework and modern .NET sometimes expect App.config to be the preferred mechanism everywhere, even though newer application models often use appsettings.json instead.
Summary
- '
App.configis the traditional XML configuration file for many .NET Framework applications.' - It commonly stores
appSettings,connectionStrings, and runtime configuration. - Code usually reads it through
ConfigurationManager. - The build output produces an executable-specific
.configfile. - '
App.configis useful for values that should change without recompiling the app.' - Avoid storing sensitive secrets in plain text configuration files when better options exist.
Related reading

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.