URGENT - C# Windows App Config File

Hi All,

For Some reason my windows app isn't pulling the config settings and it's driving me nuts.  
Added the config through solution explorer.  Named it test.config

My Config File:
<?xml version="1.0" encoding="utf-8" ?>
   <add key="dbConnString" value="server=;uid=sa;pwd=;database=Northwind" />

Accessing in the code like this:
private String dbConnString = ConfigurationSettings.AppSettings ["dbConnString"];

Am I missing something?  I haven't touched the assembly at all, do I need to add it to GAC or anything before the config will take effect?
LVL 42
Kyle AbrahamsSenior .Net DeveloperAsked:
Who is Participating?
Please create file app.config in same directory of solution.


Please create file test.exe.config in output directory (your solution directory/bin/debug).

note in particular

"The configuration file should be in the same directory as the application. The name of the configuration file should have the same name as the application with .config at the end. For example, an application called Watcher.exe should have a configuration file called Watcher.exe.config."
Kyle AbrahamsSenior .Net DeveloperAuthor Commented:
anyway to make it compile and put it in the debug bin then?
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Kyle AbrahamsSenior .Net DeveloperAuthor Commented:
Also just tried it that way (to try to brute force it)  It didn't work there either.

your config file isn't "compiled".

other key part is the name of the file.

you said test.config....

for test.exe ... it should be named test.exe.config


Kyle AbrahamsSenior .Net DeveloperAuthor Commented:
I switched  it to test.exe and test.exe.config.   Still no luck.

In addition to vinhnl's answer:

Adding App.config to your solution will allow VS.NET to compile the config file also during debugging or releasing. It will the automatically create the right filename for you.

If your application is named "test" the compiler will generate a test.exe and the configreader will look for test.exe.config. If you rename it to this filename you need to place it in the output directory, so it will be used. Biggest problem is that it wont work during debug then.

So I suggest you to use the given App.config method. That works the best for both debugging and releasing.
Kyle AbrahamsSenior .Net DeveloperAuthor Commented:
Solution presented:

I deleted ALL config files.  Created 1 new config named app.config.  It now works :-).  Thanks very much for your help.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.