Why are my application settings retrieving different values to the ones I expect?

223 views Asked by At

I have inherited an application which uses the configuration manager class to store and retrieve settings. In the app.config class there is custom section group "userSettings" which includes a "Server" property.

In the app.config file this value is defined as "a14". In Settings.Designer.vb the default is specified as "a5" yet when I try to access My.Settings.Server it brings back the value "a10", which is a value I previously used in the app.config file.

Not having much experience with the configuration manager, I am at a loss to determine where it is retrieving this value from and what I need to change so that it retrieves the correct server value.

For brevity, I have removed other settings from the code sample.

app.config:

    <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
        <section name="WorkstationApp.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />

...

<userSettings>
    <WorkstationApp.My.MySettings>
        <setting name="Server" serializeAs="String">
            <value>a14</value>
        </setting>
    </WorkstationApp.My.MySettings>
</userSettings>

Settings.Designer.vb:

    <Global.System.Configuration.UserScopedSettingAttribute(),  _
     Global.System.Diagnostics.DebuggerNonUserCodeAttribute(),  _
     Global.System.Configuration.DefaultSettingValueAttribute("a5")>  _
    Public Property Server() As String
        Get
            Return CType(Me("Server"),String)
        End Get
        Set
            Me("Server") = value
        End Set
    End Property

Application code: (server is being set to "a10", but I want it to have the app.config value of "a14").

Dim Server As String = My.Settings.Server
1

There are 1 answers

0
Jamie Alford On

It looks like I was expecting the wrong thing (well duh). I had these settings set as User settings, which are stored in the /appdata/ folder and had nothing to do with the app.config file at all.

The user config file had been set with the initial values and had never been modified subsequently with a My.Settings.Save. More details in this answer: Where are My.Settings saved in VB 2010 .NET?