Questions tagged [app-config]

.NET application configuration files contain settings specific to an application.

Application configuration files contain settings specific to an application. This file contains configuration settings that the common language runtime reads (such as assembly binding policy, remoting objects, and so on), and settings that the application can read.

The name and location of the application configuration file depend on the application's host, which can be one of the following:

Executable–hosted application.

The configuration file for an application hosted by the executable host is in the same directory as the application. The name of the configuration file is the name of the application with a .config extension. For example, an application called myApp.exe can be associated with a configuration file called myApp.exe.config.

While developing with Visual Studio the file app.config in a project will be copied to the correctly named configuration file when the project is built.

The file can contain both framework defined and user defined elements (possibly using .NET types to read and write the content).

ASP.NET-hosted application.

ASP.NET configuration files are called web.config. Configuration files in ASP.NET applications inherit the settings of configuration files in the URL path. For example, given the URL http://www.example.com/aaa/bbb, where http://www.example.com/aaa is the Web application, the configuration file associated with the application is located at www.example.com/aaa. ASP.NET pages that are in the subdirectory bbb use both the settings that are in the configuration file at the application level and the settings in the configuration file that is in bbb.

For more information about ASP.NET configuration files, see ASP.NET Configuration

Internet Explorer-hosted application. If an application hosted in Internet Explorer has a configuration file, the location of this file is specified in a tag with the following syntax:

<link rel="ConfigurationFileName" href="location">

In this tag, location is a URL to the configuration file. This sets the application base. The configuration file must be located on the same Web site as the application.

3121 questions
583
votes
15 answers

App.Config Transformation for projects which are not Web Projects in Visual Studio?

For Visual Studio 2010 Web based application we have Config Transformation features by which we can maintain multiple configuration files for different environments. But the same feature is not available for App.Config files for Windows…
Amitabh
  • 59,111
  • 42
  • 110
  • 159
439
votes
22 answers

Get connection string from App.config

var connection = ConnectionFactory.GetConnection( ConfigurationManager.ConnectionStrings["Test"] .ConnectionString, DataBaseProvider); And this is my App.config:
Moham ad Jafari
  • 4,399
  • 2
  • 15
  • 3
431
votes
29 answers

How to read AppSettings values from a .json file in ASP.NET Core

I have set up my AppSettings data in file appsettings/Config .json like this: { "AppSettings": { "token": "1234" } } I have searched online on how to read AppSettings values from .json file, but I could not get anything useful. I…
Oluwafemi
  • 14,243
  • 11
  • 43
  • 59
223
votes
7 answers

What is App.config in C#.NET? How to use it?

I have done a project in C#.NET where my database file is an Excel workbook. Since the location of the connection string is hard coded in my coding, there is no problem for installing it in my system, but for other systems there is. Is there a way…
shyam
  • 2,259
  • 2
  • 13
  • 5
219
votes
2 answers

What does 'useLegacyV2RuntimeActivationPolicy' do in the .NET 4 config?

While converting a project that used SlimDX, and therefore has unmanaged code, to .NET 4.0 I ran into the following error: Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without…
Cameron MacFarland
  • 70,676
  • 20
  • 104
  • 133
207
votes
7 answers

Is ConfigurationManager.AppSettings available in .NET Core 2.0?

I've got a method that reads settings from my config file like this: var value = ConfigurationManager.AppSettings[key]; It compiles fine when targeting .NET Standard 2.0 only. Now I need multiple targets, so I updated my project file…
Alex Sanséau
  • 8,250
  • 5
  • 20
  • 25
202
votes
17 answers

C# DLL config file

Im trying to add an app.config file to my DLL, but all attempts have failed. According to MusicGenesis in 'Putting configuration information in a DLL' this should not be a problem. So obviously I'm doing something wrong... The following code should…
MegaByte
  • 6,725
  • 10
  • 37
  • 33
187
votes
8 answers

How to find path of active app.config file?

I'm trying to finish this exception handler: if (ConfigurationManager.ConnectionStrings["ConnectionString"]==null) { string pathOfActiveConfigFile = ...? throw new ConfigurationErrorsException( "You either forgot to set the connection…
MatthewMartin
  • 32,326
  • 33
  • 105
  • 164
178
votes
5 answers

How to implement a ConfigurationSection with a ConfigurationElementCollection

I am trying to implement a custom configuration section in a project and I keep running up against exceptions that I do not understand. I am hoping someone can fill in the blanks here. I have App.config that looks like this:
Chris Holmes
  • 11,444
  • 12
  • 50
  • 64
174
votes
6 answers

Pros and cons of AppSettings vs applicationSettings (.NET app.config / Web.config)

When developing a .NET Windows Forms Application we have the choice between those App.config tags to store our configuration values. Which one is better?
Jader Dias
  • 88,211
  • 155
  • 421
  • 625
172
votes
12 answers

Can a unit test project load the target application's app.config file?

I am unit testing a .NET application (.exe) that uses an app.config file to load configuration properties. The unit test application itself does not have an app.config file. When I try to unit test a method that utilizes any of the configuration…
Jordan Parmer
  • 36,042
  • 30
  • 97
  • 119
160
votes
16 answers

Equivalent to 'app.config' for a library (DLL)

Is there an equivalent to app.config for libraries (DLLs)? If not, what is the easiest way to store configuration settings that are specific to a library? Please consider that the library might be used in different applications.
Louis Rhys
  • 34,517
  • 56
  • 153
  • 221
140
votes
7 answers

How do you pass custom environment variable on Amazon Elastic Beanstalk (AWS EBS)?

The Amazon Elastic Beanstalk blurb says: Elastic Beanstalk lets you "open the hood" and retain full control ... even pass environment variables through the Elastic Beanstalk console. http://aws.amazon.com/elasticbeanstalk/ How to pass other…
Ben
  • 4,301
  • 6
  • 37
  • 61
139
votes
8 answers

Change default app.config at runtime

I have the following problem: We have an application that loads modules (add ons). These modules might need entries in the app.config (e.g. WCF configuration). Because the modules are loaded dynamically, I don't want to have these entries in the…
Daniel Hilgarth
  • 171,043
  • 40
  • 335
  • 443
127
votes
5 answers

How should I edit an Entity Framework connection string?

I recently had to edit my app.config file to change the connection string for an Entity Framework data model (.edmx file). But I'd like to know: Is there a way to edit the EF connection string using the designer? The original connection string is…
1
2 3
99 100