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
108
votes
9 answers

The configuration element is not declared

I'm doing some work in Visual Studio 2012 Express Edition. I have added an App.config XML file as follows: The first thing that happens is a warning comes up that says "The…
Eae
  • 4,191
  • 15
  • 55
  • 92
102
votes
3 answers

Only one configSections element allowed per config file and if present must be the first child of the root configuration element

I am developing the console application and when I run the .exe file, I get the following error: system.Configuration.ConfigurationErrorsException: Only one element allowed per config file and if present must be the first child of…
Mahesh
  • 1,465
  • 4
  • 19
  • 23
101
votes
2 answers

App.config: User vs Application Scope

I have added App.config file in my project. I have created two settings from Project > Properties > Settings panel - I have noticed that when I am adding a setting, I can define scope as User or Application. - User Application If I define…
Parag Meshram
  • 8,281
  • 10
  • 52
  • 88
99
votes
2 answers

Settings.settings vs. app.config in .NET desktop app

Possible Duplicate: What is the difference between app.config file and XYZ.settings file? I am quite confused by the apparent redundancy of these two mechanisms in Visual Studio to store and manage desktop application settings: You can use the…
CesarGon
  • 15,099
  • 6
  • 57
  • 85
98
votes
15 answers

Variables within app.config/web.config

Is it is possible to do something like the following in the app.config or web.config files?
DeeStackOverflow
  • 2,741
  • 4
  • 23
  • 23
98
votes
9 answers

Developer specific app.config/web.config files in Visual Studio

We have several .NET projects where we store certain settings in configuration files. Now each developer will have their own configuration files that differ a little (different connection strings to connect to local databases, different WCF…
twarz01
  • 981
  • 1
  • 7
  • 3
97
votes
1 answer

How to create custom config section in app.config?

I want to add a custom configuration section in my app.config file. Is there a way to do it and how can I access these settings in my program. Following is the config section I want to add to my app.config:
Embedd_0913
  • 16,125
  • 37
  • 97
  • 135
90
votes
4 answers

Custom app.config section with a simple list of "add" elements

How do I create a custom app.config section that is just a simple list of add elements? I have found a few examples (e.g. How to create custom config section in app.config?) for custom sections that look like this:
Joe Daley
  • 45,356
  • 15
  • 65
  • 64
84
votes
8 answers

How to get a List collection of values from app.config in WPF?

The following example fills the ItemsControl with a List of BackupDirectories which I get from code. How can I change this so that I get the same information from the app.config file? XAML:
Edward Tanguay
  • 189,012
  • 314
  • 712
  • 1,047
81
votes
11 answers

Fix: The Global element 'configuration' has already been declared

I used the second solution of How to resolve "Could not find schema information for the element/attribute "? I.e. created a XSD with the button to create a scheme. I changed the stylesheet in app.config to app.xsd but now I get the warning: The…
Michel Keijzers
  • 15,025
  • 28
  • 93
  • 119
72
votes
13 answers

Can't read app.config in C# .NET Core unit test project with ConfigurationManager

I've created a simple unit test project to read an app.config file. Target framework is Core 2.0. I also created a Core 2.0 console app, to sanity-check myself to make sure I wasn't doing anything weird (same test passed as expected in a .NET 4.6.1…
Broots Waymb
  • 4,713
  • 3
  • 28
  • 51
70
votes
3 answers

How to make spring inject value into a static field

I know this may looks like a previously asked question but I'm facing a different problem here. I have a utility class that has only static methods. I don't and I won't take an instance from it. public class Utils{ private static Properties…
Osama FelFel
  • 1,511
  • 2
  • 15
  • 17
67
votes
5 answers

Do binding redirects in app.config for class libraries do anything?

The VS solutions I often work with consist of a single executable project (console app, web app) and many class library projects that are all referenced by the executable. When working with NuGet and installing packages, there's often an app.config…
Tom Pažourek
  • 9,582
  • 8
  • 66
  • 107
65
votes
2 answers

How do you use sections in c# 4.0 app.config?

I want to use my app config to store the settings for 2 companys, and i'd prefer if it was possible to use a section to seperate the data for one from the other rather then giving them diffrent key names. I have been checking online but i seem to…
Andy
  • 2,248
  • 7
  • 34
  • 57
61
votes
7 answers

Visual Studio: differentiate app.config for debug and release mode

Is there a way to automatically use a separate app.config when building in release mode? In other words, I want to test with one app.config, and release with another. Currently, I keep a separate copy called app.config.production, and manually…
Korey
  • 929
  • 1
  • 7
  • 14