How to find path of active app.config file?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
In a .NET application, the active configuration file at runtime is not the source app.config sitting in the project root. During build, it becomes an executable-specific config file such as MyApp.exe.config. If you need the actual file path in code, use the runtime configuration APIs rather than guessing from the project layout.
Understand Which File Is Actually Active
In classic .NET Framework projects, app.config is copied and renamed next to the executable. For example:
- source file in project:
app.config - runtime file:
bin/Debug/MyApp.exe.config
That means “find the path of app.config” really means “find the path of the runtime configuration file currently loaded by this application domain.”
The most direct way to get that path is through AppDomain.
Use AppDomain.CurrentDomain.SetupInformation.ConfigurationFile
This is the simplest and most reliable answer for many desktop and console apps.
This returns the active configuration file path being used by the current application domain.
If your goal is logging or diagnostics, this property is usually the right choice.
Use ConfigurationManager When You Also Need the Loaded Configuration
If you need both the path and the parsed configuration object, open the executable configuration explicitly.
This is useful when you need to inspect sections, app settings, or connection strings as well as the file location.
Distinguish Executable Directory from Config File Path
A common but incomplete pattern is building the path manually from the base directory and executable name.
This often works, but it is still an inferred path. Prefer the runtime-provided configuration path when possible, especially if hosting or custom setup could change resolution behavior.
Handle Unit Tests and Hosted Environments Carefully
In unit tests, Windows services, or hosted applications, the active config file may not be the one you expect from local development.
For example:
- test runners may use
testhost.dll.configor runner-specific config - Windows services may load config from the deployed service executable path
- plugins or secondary
AppDomaininstances may have different config files
That is exactly why SetupInformation.ConfigurationFile is better than hard-coded assumptions.
If you create a new application domain manually, it can have its own config:
In those cases, “active config” is domain-specific.
Read a Custom Section Once You Have the Path
Finding the path is often only step one. You may want to confirm the app is really reading the expected file.
This is a practical diagnostic pattern when configuration values differ between environments.
.NET Core and Modern .NET Note
Modern .NET applications often use appsettings.json instead of app.config. If your project is on .NET Core or .NET 5 and later and uses the generic host, the active configuration model is different.
This article applies to app.config and ConfigurationManager style applications. If you are using Host.CreateDefaultBuilder, you should inspect the configured providers instead of looking for an .exe.config file.
Common Pitfalls
One common mistake is trying to locate the original project-root app.config file at runtime. The application normally uses the copied runtime config next to the executable instead.
Another issue is constructing the path manually and assuming it always matches the active configuration. That can break in tests, hosted apps, or custom application-domain scenarios.
A third mistake is forgetting that modern .NET projects may use JSON-based configuration rather than app.config.
Summary
- The runtime config file is usually not the original source
app.config. - '
AppDomain.CurrentDomain.SetupInformation.ConfigurationFileis the most direct way to get the active config path.' - '
ConfigurationManager.OpenExeConfigurationis useful when you need both the path and loaded settings.' - Avoid hard-coded assumptions about executable layout in hosted or test environments.
- Verify which configuration system your project actually uses before debugging path issues.
Related reading
- How to find the most recent file in a directory using .NET, and without looping?
- How to find the .NET framework version of a Visual Studio project?
- How to find the Number of CPU Cores via .NET/C?
- How to Find UI thread in UWP
- How to find what state ManualResetEvent is in?
- How to find what state ManualResetEvent is in?
- How to flatten nested objects with linq expression
- How to flatten tree via LINQ?

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.