GenerateDefaultValueInCode in VS2005 and VS2008AppConfig Settings Can Be Wrong at Run Time | | GenerateDefaultValueInCode in VS2005 and VS2008 Settings.Designer, when set to true can cause you to have undesirable results at run time.
Whenever you create a web reference or add a setting in the Settings.Designer (shown below), the default action for Visual Studio is to create hard-coded defaults in the underlying generated class. This can cause major problems when moving applications to multiple environments.
If for some reason the setting does not exist in the app/web/machine config file, the program will use these defaults. This could cause your application to reference a production database from a test server or vice-versa. The symptom is shown below, with a "hard coded" connection string. This caused by setting the GenerateDefaultValueInCode to True in the Settings Designer.

In order to prevent this, you should make sure the GenerateDefaultValueInCode property is set to False for every setting in the Settings.Designer.vb file. Note that you need to show all files for the project or view the project property pages to view the settings designer. The picture shown below depicts the designer and the property that should be set to False. Failure to correct this can cause your application to fail to pick up the correct settings at run time if you are moving your application from environment to environment. Also, new settings in the appConfig file may not be picked up.

This is a problem only in VS2005 and VS2008. There was no Settings Designer in VS2003.
Have you tried our newest product, Visual Class Organizer? You'll be amazed how easy it is to keep the code in your code windows organized. TRY IT FREE FOR 30 DAYS BY CLICKING HERE.
If you are developing in C# and haven't tried CSharpCompleter, you are wasting valuable time typing hundreds of braces {} daily needlessly. Try CSharpCompleter for 30 DAYS FREE.
| Ask a Question, or give your feedback on my articles or products by going to the KnowDotNet Forum or by clicking on My Blog. |  |
|