views:

80

answers:

2

I have used Visual Studio to generate a class for application settings in a windows forms application. The application settings aren't populated with values when debugging. Why are there no values?

Here is the generated code:

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.1
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace Unidata_Client.Properties {


    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")]
    internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {

        private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));

        public static Settings Default {
            get {
                return defaultInstance;
            }
        }

        [global::System.Configuration.UserScopedSettingAttribute()]
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
        [global::System.Configuration.DefaultSettingValueAttribute("blah")]
        public string UnidataUsername {
            get {
                return ((string)(this["UnidataUsername"]));
            }
            set {
                this["UnidataUsername"] = value;
            }
        }

        [global::System.Configuration.UserScopedSettingAttribute()]
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
        [global::System.Configuration.DefaultSettingValueAttribute("blah")]
        public string UnidataPassword {
            get {
                return ((string)(this["UnidataPassword"]));
            }
            set {
                this["UnidataPassword"] = value;
            }
        }

        [global::System.Configuration.UserScopedSettingAttribute()]
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
        [global::System.Configuration.DefaultSettingValueAttribute("blah")]
        public string UnidataHost {
            get {
                return ((string)(this["UnidataHost"]));
            }
            set {
                this["UnidataHost"] = value;
            }
        }

        [global::System.Configuration.UserScopedSettingAttribute()]
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
        [global::System.Configuration.DefaultSettingValueAttribute("123")]
        public string UnidataPort {
            get {
                return ((string)(this["UnidataPort"]));
            }
            set {
                this["UnidataPort"] = value;
            }
        }

        [global::System.Configuration.UserScopedSettingAttribute()]
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
        [global::System.Configuration.DefaultSettingValueAttribute("blah")]
        public string UnidataAccount {
            get {
                return ((string)(this["UnidataAccount"]));
            }
            set {
                this["UnidataAccount"] = value;
            }
        }
    }
}

Here is the app.config file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
            <section name="Unidata_Client.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
        </sectionGroup>
    </configSections>
    <userSettings>
        <Unidata_Client.Properties.Settings>
            <setting name="UnidataUsername" serializeAs="String">
                <value>blah</value>
            </setting>
            <setting name="UnidataPassword" serializeAs="String">
                <value>blah </value>
            </setting>
            <setting name="UnidataHost" serializeAs="String">
                <value>blah</value>
            </setting>
            <setting name="UnidataPort" serializeAs="String">
                <value>123</value>
            </setting>
            <setting name="UnidataAccount" serializeAs="String">
                <value>blah</value>
            </setting>
        </Unidata_Client.Properties.Settings>
    </userSettings>
</configuration>

Here is how I am using the settings:

 using (var session = UniObjects.OpenSession(Settings.Default.UnidataHost,
                int.Parse(Settings.Default.UnidataPort),
                Settings.Default.UnidataUsername,
                Settings.Default.UnidataPassword,
                Settings.Default.UnidataAccount,
                "udcs"))
            {
                .....
            } 
A: 

Is your app.config being copied and renamed to MyApp.exe.config in your debug output directory?

chibacity
Yes it is [comments require too many characters]
Ronnie Overby
And if you are running with a debugger attached, are the settings present in the MyApp.vshost.exe.config file?
chibacity
A: 

You are using "usersettings" (scope "user" in the designer).
When changed (not default) these settings are stored somewhere in your personal profile.
These settings override the ones in the directory of your application

Could you try to change the settings to scope "application" in the designer and run again ?

If you have values then, u can be sure the usersettings are overridden in your profile directory.

Look for a file user.config in C:\Users\XX\AppData\Local\ApplicationName\Version\

Julian de Wit