Bali C
Bali C

Reputation: 31231

Do I need app.config?

I have made a app which uses visual studio's app.config to store settings about the checkboxes states etc which works fine. I copied the exe for the app from the default directory and ran it, I forgot about the app.config file but it still worked as normal, is app.config compiled into the exe somehow, or do I still need to include it in the same folder as the exe? Thanks.

Upvotes: 4

Views: 3965

Answers (4)

TobyEvans
TobyEvans

Reputation: 1461

App.config will be renamed during the build to match the application name, so for "myApp", you will get "myApp.exe" and "myApp.exe.config".

Are you sure you are definitely accessing the config file, or running the right exe? Silly questions, but worth checking. If you're just storing the settings, you might be able to run the app and not see a problem unless you actually try to save. Not saying that is what is happening, just possible.

As I recall from my .net days, saving to the default config file was much harder than reading - are you sure you are saving to that?

Upvotes: 1

AVee
AVee

Reputation: 3402

Visual Studio will generate a .exe.config file which contains the settings from the app.config when building. That's the file which is used to store settings when running the application. You should copy that file, the app.config isn't needed.

Upvotes: 1

Michael Edenfield
Michael Edenfield

Reputation: 28338

If the app.config file is missing from the execution folder, all attempts to read the application settings will return null values; depending on what mechanism you use to reload the settings, that will either result in null reference exceptions, or else just use default values for everything.

Also, note that app.config is the design-time name for the file. At run-time, your app will actually look for ExecutableFile.exe.config. You may have copied it over without realizing it.

Upvotes: 2

Matthew Abbott
Matthew Abbott

Reputation: 61589

App.config files (which on build/deployment would be copied as something like MyApplication.exe.config are only required, if you have coded your application in such a way that it is explicitly dependent on it. If you have not done this, or have put error handling/default values or actions in place where it can't read the config file, one would assume your application could run without it.

Upvotes: 3

Related Questions