0

Thanks to Is there a config type file for Visual Studio Add-In? I was able to create an app.config file for the Visual Studio add-in I am developing with the ability to read/write to it.

Now I am having trouble saving the changes made to it at runtime. I have been running the following test code, but when I look the app.config file after running in debug, nothing has changed.

Dim pluginAssemblyPath As String = Assembly.GetExecutingAssembly().Location
Dim configuration As Configuration = ConfigurationManager.OpenExeConfiguration(pluginAssemblyPath)
Dim test1 As String = configuration.AppSettings.Settings.Item("Key1").Value

configuration.AppSettings.Settings.Item("Key1").Value = "Is this thing on?"

Dim test3 As String = configuration.AppSettings.Settings.Item("Key1").Value
configuration.AppSettings.SectionInformation.ForceSave = True
configuration.Save(ConfigurationSaveMode.Modified)
Community
  • 1
  • 1
user3712663
  • 21
  • 1
  • 4
  • Check this out http://www.neolisk.com/techblog/vbnet-read-write-appconfig (full disclosure - this is my article) – Victor Zakharov Jul 30 '14 at 16:15
  • This was not helpful, but I had someone else help me out: ConfigurationManager.RefreshSection("appSettings") Use that after the last line of what I have above. The actually app.config file will not change, but the config file inside of bin does. – user3712663 Aug 01 '14 at 19:13

1 Answers1

0
Dim pluginAssemblyPath As String = Assembly.GetExecutingAssembly().Location
   'Dim configuration As Configuration = ConfigurationManager.OpenExeConfiguration(pluginAssemblyPath)
    Dim test1 As String = configuration.AppSettings.Settings.Item("Key1").Value

    configuration.AppSettings.Settings.Item("Key1").Value = "Is this thing on?"

    Dim test3 As String = configuration.AppSettings.Settings.Item("Key1").Value
    configuration.AppSettings.SectionInformation.ForceSave = True
    configuration.Save(ConfigurationSaveMode.Modified)
    ConfigurationManager.RefreshSection("appSettings")

The actual app.config will not change, but the config file inside of the bin folder does.

user3712663
  • 21
  • 1
  • 4