app-config

App.Config change value

帅比萌擦擦* 提交于 2019-11-26 01:53:34
问题 This is my App.Config <?xml version=\"1.0\" encoding=\"utf-8\" ?> <configuration> <appSettings> <add key=\"lang\" value=\"English\"/> </appSettings> </configuration> With this code I make the change lang = \"Russian\"; private void Main_FormClosing(object sender, FormClosingEventArgs e) { System.Configuration.ConfigurationManager.AppSettings.Set(\"lang\", lang); } But it not change. What I\'m doing wrong? 回答1: You cannot use AppSettings static object for this. Try this string appPath = System

Get connection string from App.config

南笙酒味 提交于 2019-11-26 01:35:24
问题 var connection = ConnectionFactory.GetConnection( ConfigurationManager.ConnectionStrings[\"Test\"] .ConnectionString, DataBaseProvider); And this is my App.config: <?xml version=\"1.0\" encoding=\"utf-8\" ?> <configuration> <connectionStrings> <add name=\"Test\" connectionString=\"Data Source=.;Initial Catalog=OmidPayamak;Integrated Security=True\" providerName=\"System.Data.SqlClient\" /> </connectionStrings> </configuration> But when my project runs this is my error: Object reference not

What is App.config in C#.NET? How to use it?

时间秒杀一切 提交于 2019-11-25 23:46:02
问题 I have done a project in C#.NET where my database file is an Excel workbook. Since the location of the connection string is hard coded in my coding, there is no problem for installing it in my system, but for other systems there is. Is there a way to prompt the user to set a path once after the setup of the application is completed? The answers I got was \"Use App.Config\"... can anyone tell what is this App.config and how to use it in my context here? 回答1: At its simplest, the app.config is

What does &#39;useLegacyV2RuntimeActivationPolicy&#39; do in the .NET 4 config?

陌路散爱 提交于 2019-11-25 23:43:48
问题 While converting a project that used SlimDX, and therefore has unmanaged code, to .NET 4.0 I ran into the following error: Mixed mode assembly is built against version \'v2.0.50727\' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information. Googling around gave me the solution, which is to add this to the applications config: <configuration> <startup useLegacyV2RuntimeActivationPolicy=\"true\"> <supportedRuntime version=\"v4.0\"/> </startup> <

Change default app.config at runtime

北慕城南 提交于 2019-11-25 22:48:13
问题 I have the following problem: We have an application that loads modules (add ons). These modules might need entries in the app.config (e.g. WCF configuration). Because the modules are loaded dynamically, I don\'t want to have these entries in the app.config file of my application. What I would like to do is the following: Create a new app.config in memory that incorporates the config sections from the modules Tell my application to use that new app.config Note: I do not want to overwrite the

C# DLL config file

佐手、 提交于 2019-11-25 22:40:27
问题 Im trying to add an app.config file to my DLL, but all attempts have failed. According to MusicGenesis in \'Putting configuration information in a DLL\' this should not be a problem. So obviously I\'m doing something wrong... The following code should return my ConnectionString from my DLL: return ConfigurationManager.AppSettings[\"ConnectionString\"]; However, when I copy the app.config file to my console application, it works fine. Any ideas? 回答1: It is not trivial to create a .NET

App.Config Transformation for projects which are not Web Projects in Visual Studio?

[亡魂溺海] 提交于 2019-11-25 22:34:41
问题 For Visual Studio 2010 Web based application we have Config Transformation features by which we can maintain multiple configuration files for different environments. But the same feature is not available for App.Config files for Windows Services/WinForms or Console Application. There is a workaround available as suggested here: Applying XDT magic to App.Config. However it is not straightforward and requires a number of steps. Is there an easier way to achieve the same for app.config files?