1

i have simple problem: i added reference:

System.Configuration

and two using names:

  • System.Configuration;
  • System.Collection.Specialized;

it's my App1.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="MyKey" value="MyValue"/>
  </appSettings>
  <connectionStrings>
    <add name ="MyHost"
         providerName="System.Data.Sql"
         connectionString="Data Source=(local)\SQLEXPRESS;Initial Catalog=Northwind;
                           Integrated Security = true; User ID=Admin;Password=P@ssw0rd;
                           Connection Timeout=2;Encrypt=True;TrustServerCertificate=True" />
  </connectionStrings>
</configuration>

and when i would connect to my database, all is OK! (by this way):

ConnectionStringSettingsCollection settings = ConfigurationManager.ConnectionStrings;
            if(settings != null)
                MessageBox.Show(settings[0].ConnectionString, "ConnectionString");

but when i would get value for property MyKey, then string's null, looks like:

string s = ConfigurationManager.AppSettings["MyKey"];

what i do wrong?

EDIT: it's debug view:enter image description here

Marek Woźniak
  • 1,766
  • 16
  • 34

1 Answers1

0

I can't have fileName for configuration App1.config, only App.config is accept.

Marek Woźniak
  • 1,766
  • 16
  • 34
  • 1
    The real reason for this is because when you compile your application, it renames `App.config` into `.exe.config`. So if you have a file that is anything different than `App.config`, visual studio won't know what to transform. – gunr2171 Jul 24 '14 at 15:56
  • Good question. You might have had a loose file somewhere. But there is not enough info to figure that out. If it's really a problem, post another question. – gunr2171 Jul 24 '14 at 16:00
  • @W92 hmmm.. your profile pic is misleading. i thought there is a housefly in my monitor... even tried to touch with my hand to move it away.... – suhailvs Aug 12 '14 at 12:38