0

I was wondering, is there any way to ensure that an app.config will not turn out to be missing when an app's passed to another user/computer? My senior gave me an assignment for the app to automatically create an app.config with settings in it if an app.config is missing or deleted by the user. (So now he's testing on deleting the config file that came along with the .exe and .dlls) But I'm thinking that it probably doesn't have to be this way. There must be something, some solution to avoid user accidentally deleting the config file. Or if it's indeed deleted or deemed missing, some sort of retrieval method or recreate method. My senior insists that the app must have the function to create a new config file. And I want to insist that there's a different way to approach this.

Kurisuchin
  • 155
  • 1
  • 4
  • 20
  • It is a good idea to validate the app settings at startup. The invalid and missing values could be handled by resetting them to a default value and / or by informing the user. Preventing users from changing the config file is the job of sysadmins. – TAMTAM Apr 02 '15 at 07:35

1 Answers1

0

See this question. When your application is first started, you can recreate app.config and then create another AppDomain.

Community
  • 1
  • 1
Dmitry Arestov
  • 1,427
  • 12
  • 24
  • What is exactly the purpose of doing so? – Kurisuchin Apr 02 '15 at 06:06
  • I don't know. The author wishes to do so. If you merely recreate the file within the default appdomain and then do restart, then you will have to save `app.config` near to the .exe file. But this location is likely to be read-only (ProgramFiles). When creating another domain, you can set any location using `AppDomain.CurrentDomain.SetupInformation.ConfigurationFile`. – Dmitry Arestov Apr 02 '15 at 08:49