configurationmanager

Using .NET ConfigurationManager to read settings from a string instead of an app.config file

与世无争的帅哥 提交于 2019-12-06 08:17:19
We are running multiple instances of our service (implemented as a .exe file) on different machines in our data center. However, we would like to store configuration parameters for this .exe file in a central location (as opposed to being in the .exe.config per machine). To do this, we are planning to move the content of the .exe.config files to an attribute in a central repository (Active Directory or SQL) and make the .exe's running on all machines read from this repository. I would like reuse all the existing classes used for reading/writing configuration information (using

Reading and writing values in.NET .config files

人走茶凉 提交于 2019-12-06 06:39:44
I want to use a custom path for a user.config file, rather than have .NET read it from the default location. I am opening the file like this: ExeConfigurationFileMap configMap = new ExeConfigurationFileMap(); configMap.ExeConfigFilename = String.Format("{0}\\user.config",AppDataPath); Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configMap, ConfigurationUserLevel.PerUserRoamingAndLocal); But I can't figure out how to actually read settings out of it, I get a compile error saying that the values are inaccessible when I try to get a value through AppData or

Accessing ConfigurationManager.AppSettings value from Spring.NET xml configuration

元气小坏坏 提交于 2019-12-06 00:56:27
问题 I have a requirement that requires me to use Spring.net to get a connectionstring that is stored inside the app.config, and then inject the retrieved connectionstring to a instantiated object. How can I do this using Spring.net's xml configuration? For e.g., instead of my codes doing this: // Spring.net config: <object name="myService" type="com.acme.MyService, com.acme"> <constructor-arg type="System.String" value="myConnectionName"/> </object> // Web.config: <connectionStrings> <add name=

ConfigurationManager.GetSection(sectionName) returns null while performing unit tests

我的未来我决定 提交于 2019-12-06 00:31:34
问题 I have a unit tests project with it's own app.config file, which is a mock of a real configuration file defined by target project being tested. This mock file is loaded and processed by unit test code (not by target project), and it works properly if I run only tests within only this one test project. ConfigurationManager.GetSection(sectionName) However, if I run tests from several test projects, and other test projects are performed prior to relevant project, the above statement returns null

ConfigurationManager Save() wants to create a tmp-File

跟風遠走 提交于 2019-12-05 12:05:56
I am having problems with a application that wants to write to the .exe.config. See following code: using System; using System.Configuration; using System.IO; namespace ConfigurationManagerError { class Program { static void Main(string[] args) { try { // set Config-File to persistent folder ExeConfigurationFileMap exeMap = new ExeConfigurationFileMap(); exeMap.ExeConfigFilename = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "ConfigError\\ConfigurationManagerError.exe.config"); Configuration config = ConfigurationManager.OpenMappedExeConfiguration

Getting a StringCollection out of AppSettings through the configuration manager

你说的曾经没有我的故事 提交于 2019-12-05 10:39:39
I am accessing my assembly's configuration like this: ExeConfigurationFileMap map = new ExeConfigurationFileMap(); map.ExeConfigFilename = Assembly.GetExecutingAssembly().Location + ".config"; Configuration conf = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None); AppSettingsSection appSettings = conf.AppSettings; My .config file contains a section like this <configSections> <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" > <section name=

Using a LINQ Where query to get only some of the ConfigurationManager.ConnectionStrings

此生再无相见时 提交于 2019-12-05 04:28:32
My goal is to use a LINQ Where query on the ConfigurationManager.ConnectionStrings collection in a console application (assume a fresh .NET 4.5 console application with a System.Configuration reference added, and a correspodning using statement). I started with this, which does not work : var relevantSettings = ConfigurationManager.ConnectionStrings.Where(s => s.Name.StartsWith("Xyz")); It tells me that: The type arguments for method ' IEnumerable<TSource> System.Linq.Enumerable.Where<TSource(this IEnumerable<TSource>, Func<TSource,bool>) ' cannot be inferred from the usage. Try specifying the

How to open a SectionGroup in an ASP.NET web application?

强颜欢笑 提交于 2019-12-05 02:06:48
I have a small ASP.NET web application hosted in an integration test (executing within NUnit). My product code can usually find configuration data from the web.config or app.config file, but for some reason when hosting ASP.NET I seem to get an ArgumentException when executing the first of these commands: var configuration = ConfigurationManager.OpenExeConfiguration(null); return configuration.GetSectionGroup(SectionGroupName); exePath must be specified when not running inside a stand alone exe. I don't know what to put here. There isn't a sensible exePath for my product to ever pass into this

How to make ConfigurationManager read a config file other than app.config?

夙愿已清 提交于 2019-12-04 23:54:01
I need to parse a config file that is situated in another project. I know that ConfigurationManager reads the app.config file by default, but how to make it read that particular config file? // Create a filemap refering the config file. ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap(); fileMap.ExeConfigFilename = configFilePath; // Retrieve the config file. Configuration configuration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None); Or like this: var fileMap = new ConfigurationFileMap(configFilePath); Configuration config =

Change in AppSettings needs restart my Application how can I avoid?

久未见 提交于 2019-12-04 11:18:33
问题 I'm using C# .NET 2.0 Windows Application. and I'm using app.config for my Application Settings. but change in AppSettings doesn't reflected runtime, it Needs Application to be restarted. How can I avoid it. Here is my code snippet I used to read and write the Application Settings. I'm reading the Setting like this string temp = ConfigurationManager.AppSettings.Get(key); I'm updating the value like this where node is the current configuration/appSettings Node node.Attributes["value"].Value =