0

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
Jamie Alford
  • 95
  • 11
  • Try deleting the project's `Bin` and `Debug` folders? One of these may contain an old version of `app.config`. – groverboy Dec 15 '16 at 05:36
  • Sorry, still coming back with a10. Good suggestion though. – Jamie Alford Dec 15 '16 at 05:52
  • I have resolved this issue by starting the application, changing the value of the settings and then using my.settings.save to save the new values. I still would like to know where it was writing this data though. – Jamie Alford Dec 15 '16 at 06:59
  • Difficult to guess without seeing all of the code. Could be that during initialize the setter executes more than once. I would set a breakpoint on the setter to confirm. If it breaks a second time on the setter, check the call stack at that point. – groverboy Dec 16 '16 at 09:15

1 Answers1

1

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?

Community
  • 1
  • 1
Jamie Alford
  • 95
  • 11