configurationmanager

Differences in behavior between System.Web.Configuration.WebConfigurationManager and System.Configuration.ConfigurationManager

岁酱吖の 提交于 2019-11-30 12:10:20
问题 I had some trouble on a test server with an ASP.NET website. I goofed, and had the home directory of the Default Web Site pointed to the wrong place. When I tried: ConfigurationManager.ConnectionStrings["connectionString"]; it returned null, but using System.Web.Configuration; /* ... */ var rootWebConfig = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath); WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath); rootWebConfig.ConnectionStrings

How do you instruct NUnit to load an assembly's dll.config file from a specific directory?

╄→гoц情女王★ 提交于 2019-11-30 11:43:56
If an assembly contains an app.config file, ConfigurationManager will load it as long as it is in the same directory as the NUnit project that is executing through NUnit-Gui. To illustrate consider the following folder structure. + TestFolder testProject.nunit + AssemblyAFolder assemblyA.dll assemblyA.dll.config + AssemblyBFolder assemblyB.dll assemblyB.dll.config Both AssemblyA and AssemblyB exercise code that calls into ConfigurationManager . If I run these test assemblies independently in NUnit-Gui, ConfigurationManager will correctly resolve the local configuration files. However, if I

How do I select a .Net application configuration file from a command line parameter?

末鹿安然 提交于 2019-11-30 11:19:55
I would like to override the use of the standard app.config by passing a command line parameter. How do I change the default application configuration file so that when I access ConfigurationManager.AppSettings I am accessing the config file specified on the command line? Edit: It turns out that the correct way to load a config file that is different than the name of the EXE plus .config is to use OpenMappedExeConfiguration. E.g. ExeConfigurationFileMap configFile = new ExeConfigurationFileMap(); configFile.ExeConfigFilename = Path.Combine(Environment.CurrentDirectory, "Shell2.exe.config");

Where is ConfigurationManager's namespace?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-30 10:50:05
I've got a reference to System.Configuration - and ConfigurationSettings is found no problem - but the type or namespace ' ConfigurationManager ' could not be found!? I've read around - and it looks like it should belong to the same namespace as the ConfigurationSettings class. EDIT: Please take note - I've clearly said I have added a reference to System.Configuration . There's been 4 comments already about this. ConfigurationManager is a part of the System.Configuration after .Net 2.0. Add a reference to the System.Configuration dll. Try using System.Configuration.ConfigurationManager. You

The problem with NUnit and app.config

谁说胖子不能爱 提交于 2019-11-30 08:08:13
When i run a simple test on connection to DB check i receive an error in NUnit: [Test] public void TestConn() { string connectionString = ConfigurationManager.ConnectionStrings["FertigungRead"].ConnectionString; SqlConnection connection = new SqlConnection(connectionString); connection.Open(); Assert.AreEqual(ConnectionState.Open, connection.State); connection.Close(); } System.NullReferenceException : Object reference not set to an instance of an object. on line : connectionString = ConfigurationManager.ConnectionStrings["FertigungRead"].ConnectionString; Can i use ConfigurationManager in

ConfigurationManager.AppSettings Caching

天大地大妈咪最大 提交于 2019-11-30 07:49:56
We know that IIS caches ConfigurationManager.AppSettings so it reads the disk only once until the web.config is changed. This is done for performance purposes. Someone at: http://forums.asp.net/p/1080926/1598469.aspx#1598469 stated that .NET Framework doesn't do the same for app.config, but it reads from the disk for every request. But I find it hard to believe, 'cause it would be slower. Please tell me that he is wrong or I'll have to fix every Console/Windows Forms/Windows Services I wrote. Update I regret that I misinterpreted what people said in the linked forum above. A quick test seems

Differences in behavior between System.Web.Configuration.WebConfigurationManager and System.Configuration.ConfigurationManager

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-30 02:09:55
I had some trouble on a test server with an ASP.NET website. I goofed, and had the home directory of the Default Web Site pointed to the wrong place. When I tried: ConfigurationManager.ConnectionStrings["connectionString"]; it returned null, but using System.Web.Configuration; /* ... */ var rootWebConfig = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath); WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath); rootWebConfig.ConnectionStrings.ConnectionStrings["connectionString"].ConnectionString;` returned the correct connection string. What are all the

Visual Studio: Configuration Manager missing

99封情书 提交于 2019-11-30 00:48:31
问题 I'm using Microsoft Visual Studio Team System 2008 Team Suite. The "Configuration Manager" menu item is missing for me. I've assigned a keyboard shortcut to the Configuration Manager, but it doesn't have any effect (actually, it produces a "ding" sound). How do I get the Configuration Manager to work for all projects? 回答1: The answer is: Make sure the following option is checked: Tools ⇒ Options ⇒ Projects and Solutions ⇒ General ⇒ "Show advanced build configurations". 回答2: Visual Studio 2008

Does ConfigurationManager.AppSettings[Key] read from the web.config file each time?

青春壹個敷衍的年華 提交于 2019-11-29 23:08:52
I'm just wondering how the ConfigurationManager.AppSettings[Key] works? Does it read from the physical file each time I need a key? If so, should I be reading all the app settings of my web.config in a cache and then read from it? Or ASP.NET or IIS loads the web.config file at application_startup and only once. How to verify whether the physical file is accessed by each read? If I change the web.config, IIS restarts my application so can't verify it that way. Thanks, dash It gets cached, on first access of a property, so it does not read from the physical file each time you ask for a value.

ConfigurationProperty is inaccessible due to its protection level

喜欢而已 提交于 2019-11-29 18:20:50
问题 I wanna read/write (and save) application's configuration file in program The app.config is like this: <configuration> <configSections> <section name="AdWordsApi" type="System.Configuration.DictionarySectionHandler" requirePermission="false"/> </configSections> <AdWordsApi> <add key="LogPath" value=".\Logs\"/> ... </AdWordsApi> </configuration> When I use ConfigurationManager.GetSection to read the app.config, it works: var adwords_section = (System.Collections.Hashtable) System.Configuration