app-config

Create app config file if doesn't exist C#

大城市里の小女人 提交于 2019-12-19 07:09:29
问题 When I try to open my app config file by ConfigurationManager.OpenExeConfiguration(filePath); it returns an exception, because there is no file. But I need to create this file in this case. But as I know, config file create by adding at VS like How to: Add an Application Configuration File to a C# Project So, how to create this file in other way? 回答1: If you really want to create an empty config file at runtime you can do something like this, but note that if the config file already exists

app.configs and MSTest Project - null reference for a connection string

此生再无相见时 提交于 2019-12-19 05:53:53
问题 When I try to run Unit Tests (mstest) I run into this issue. The line of code: _mainCnStr = System.Configuration.ConfigurationManager. ConnectionStrings["main"].ConnectionString; Comes back as a null reference It doesn't do this in the main UI project when I run it. What is the right method to get this connection string setting seen by the Unit Test project? I tried embedded as a resource. I tried Copy Always. What is the right combination of settings that will fix this for me? 回答1: One thing

What happens to app.config in a referenced project

廉价感情. 提交于 2019-12-18 19:18:19
问题 Say I have 2 projects, where project A references project B. Project A is a web application project and project B is a class library. The class library has an app.config file where some settings are stored. When I compile project A, projectB.dll is created in the bin folder. What happens to the contents of the app.config file when the web application is deployed? Are the settings compiled into ProjectB.dll? Is it possible to retrieve the contents of the app.config using a tool like reflector

app.config multiple values by single key [duplicate]

我怕爱的太早我们不能终老 提交于 2019-12-18 18:51:32
问题 This question already has answers here : Multiple values for a single config key (9 answers) Closed 5 years ago . is it possible to have app.config file like this : <?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> <add key="someKey" value="valueHere"/> <add key="anotherKey" value="valueHere"/> <add key="listOfValues"> <value1/> ... <valueN/> </add> </appSettings> </configuration> I mean, I want to have a key in config file that returns a list of values.How to do it? Think

app.config multiple values by single key [duplicate]

和自甴很熟 提交于 2019-12-18 18:49:55
问题 This question already has answers here : Multiple values for a single config key (9 answers) Closed 5 years ago . is it possible to have app.config file like this : <?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> <add key="someKey" value="valueHere"/> <add key="anotherKey" value="valueHere"/> <add key="listOfValues"> <value1/> ... <valueN/> </add> </appSettings> </configuration> I mean, I want to have a key in config file that returns a list of values.How to do it? Think

Escape & in App.config

泄露秘密 提交于 2019-12-18 12:45:34
问题 I have the following piece of config in my App.config file: <add key="ConnectionString" value="INITIAL CATALOG=myDatabase;DATA SOURCE=myServer;User ID=myUser;Password=!&myPass99;"/> The above connection string is rejected by Visual Studio intellisense. It says entity myPass99 not defined. The problem is caused by the & in the password. How do I escape it? 回答1: Escape the ampersand by using & in place of the & As an FYI, see here for further characters: What characters do I need to escape in

The problem with NUnit and app.config

拜拜、爱过 提交于 2019-12-18 12:06:00
问题 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 =

Can several WCF services share a common BaseAddress?

倖福魔咒の 提交于 2019-12-18 11:11:30
问题 I've got an assembly containing several WCF services, each with its own contract. It all works nicely. The service config in the app.config for the service looks like this: <services> <service behaviorConfiguration="WcfService.AlyzaServiceBehavior" name="Sam.Alyza.WcfService.ServiceWebsites"> <endpoint address="" binding="netTcpBinding" contract="Sam.Alyza.WcfInterface.IServiceWebsites"> <identity> <dns value="localhost" /> </identity> </endpoint> <endpoint address="mex" binding=

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

吃可爱长大的小学妹 提交于 2019-12-18 10:49:11
问题 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 overwrite bin\Release\Application.exe.config after building for release. 回答1: Unload project in the solution explorer via contet menu. Edit .csproj file. Add this strings into file. <PropertyGroup> <AppConfig>App.$(Configuration).config</AppConfig> <

How to include simple collections in ConfigurationSection

对着背影说爱祢 提交于 2019-12-18 07:34:34
问题 Is there a way for me to include a simple array of strings, or List<string> on my custom subclass of ConfigurationSection? (Or an array or generic list of simple data objects, for that matter?) I'm becoming familiar with the new (and VERY verbose) ConfigurationSection, ConfigurationElement, and ConfigurationElementCollection classes, but I'm by no means an expert yet. It seems like ConfigurationSection should handle simple collections/lists on its own, without me having to create a custom