configurationmanager

ConfigurationManager.OpenExeConfiguration - loads the wrong file?

╄→гoц情女王★ 提交于 2019-11-27 08:34:06
I have added multiple app.config (each with a differet name) files to a project, and set them to copy to the output directory on each build. I try and access the contents of each file using this: System.Configuration.Configuration o = ConfigurationManager.OpenExeConfiguration(@"app1.config"); The code runs, but o.HasFile ends up False, and o.FilePath ends up "app1.config.config". If I change to code: System.Configuration.Configuration o = ConfigurationManager.OpenExeConfiguration(@"app1"); Then the code bombs with "An error occurred loading a configuration file: The parameter 'exePath' is

Changing App.config at Runtime

风流意气都作罢 提交于 2019-11-27 08:30:30
I'm writing a test WinForms / C# / .NET 3.5 application for the system we're developing and we fell in the need to switch between .config files at runtime, but this is turning out to be a nightmare. Here's the scene: the WinForms application is aimed at testing a WebApp, divided into 5 subsystems. The test process works with messages being sent between the subsystems, and for this process to be successful each subsystem got to have its own .config file. For my Test Application I wrote 5 separate configuration files. I wish I was able to switch between these 5 files during runtime, but the

System.Configuration.ConfigurationManager not available?

て烟熏妆下的殇ゞ 提交于 2019-11-27 02:02:09
问题 In a VS2005 C# project I have added a reference to System.configuration. In the object browser, I can see the System.Configuration.ConfigurationManager. In Intellisense System.Configuration only has the old ConfigurationSettings, and not ConfigurationManager. My code System.Configuration.ConfigurationManager.AppSettings["MySetting"] is highlighted as a syntax error and does not compile. In a different project, the exact same setup works just fine... any clues as to what is going on? 回答1:

Loading System.ServiceModel configuration section using ConfigurationManager

可紊 提交于 2019-11-27 00:12:48
问题 Using C# .NET 3.5 and WCF, I'm trying to write out some of the WCF configuration in a client application (the name of the server the client is connecting to). The obvious way is to use ConfigurationManager to load the configuration section and write out the data I need. var serviceModelSection = ConfigurationManager.GetSection("system.serviceModel"); Appears to always return null. var serviceModelSection = ConfigurationManager.GetSection("appSettings"); Works perfectly. The configuration

Is there a way to get a System.Configuration.Configuration instance based on arbitrary xml?

为君一笑 提交于 2019-11-26 23:15:51
问题 I'm trying to unit test a custom ConfigurationSection I've written, and I'd like to load some arbitrary configuration XML into a System.Configuration.Configuration for each test (rather than put the test configuration xml in the Tests.dll.config file. That is, I'd like to do something like this: Configuration testConfig = new Configuration("<?xml version=\"1.0\"?><configuration>...</configuration>"); MyCustomConfigSection section = testConfig.GetSection("mycustomconfigsection"); Assert.That

Accessing another projects app.config properties?

久未见 提交于 2019-11-26 20:54:39
问题 I have two projects within my solution, for this example I will call them project A and B. Project B references A. Can Project B access the app.config properties of project A? I wish to access an app key string within the app.config of A. string tfsUri = ConfigurationManager.AppSettings["TfsUri"]; 回答1: That's generally not a good idea, as you introduce hard dependencies between the projects. So if you can copy-paste config value, that will make your projects self-contained (however, this

What's the difference between the WebConfigurationManager and the ConfigurationManager?

旧城冷巷雨未停 提交于 2019-11-26 18:43:39
What's the difference between the WebConfigurationManager and the ConfigurationManager ? When should I use one over the other? UPDATED I just looked at the WebConfigurationManager , and for some reason, you can't access the connection strings as you do in the ConfigurationManager (like an array). Can anyone tell me why MS made it like this? It seems to be a pain to get the connection string you need using the WebConfigurationManager . UPDATED AGAIN with CAVEAT! If you don't have a reference to the System.Configuration namespace added to your project, then Visual Studio will show an error when

How to get the values of a ConfigurationSection of type NameValueSectionHandler

本小妞迷上赌 提交于 2019-11-26 15:51:34
问题 I'm working with C#, Framework 3.5 (VS 2008). I'm using the ConfigurationManager to load a config (not the default app.config file) into a Configuration object. Using the Configuration class, I was able to get a ConfigurationSection , but I could not find a way to get the values of that section. In the config, the ConfigurationSection is of type System.Configuration.NameValueSectionHandler . For what it worth, when I used the method GetSection of the ConfigurationManager (works only when it

How to find path of active app.config file?

◇◆丶佛笑我妖孽 提交于 2019-11-26 15:03:56
问题 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 string, or " + "you're using a unit test framework that looks for "+ "the config file in strange places, update this file : " + pathOfActiveConfigFile); } This problem seems to only happen to me when I'm using nUnit. 回答1: Try this AppDomain.CurrentDomain

ConfigurationManager.OpenExeConfiguration - loads the wrong file?

女生的网名这么多〃 提交于 2019-11-26 14:11:46
问题 I have added multiple app.config (each with a differet name) files to a project, and set them to copy to the output directory on each build. I try and access the contents of each file using this: System.Configuration.Configuration o = ConfigurationManager.OpenExeConfiguration(@"app1.config"); The code runs, but o.HasFile ends up False, and o.FilePath ends up "app1.config.config". If I change to code: System.Configuration.Configuration o = ConfigurationManager.OpenExeConfiguration(@"app1");