views:

56

answers:

2

How can I prevent .NET from using the compiled .config settings when no config file is present?

For example, I have a connection string setting in the app.config file that specifies a development server. When built, this produces an .exe.config file. And all is well.

However, if you ever forget to tote along the .exe.config file, the application will happily - and without warning - use the values that were specified in the designer (app.config).

Is there any way to cause a .NET assembly to throw an exception instead of silently using values that were specified during development?

+1  A: 

You could place a default value in the settings designer, that you detect at runtime.

Perhaps make the connection string setting = "NOTSET", detect and throw if found.

Mitch Wheat
A: 

On the Settings pane there is a GenerateDefaultValueInCode property for each setting, which by default is set to true.

If you set it to false and no .config file is found an empty string is returned for that setting. I'm not sure how it would work for other datatypes.

jakdep