dcsimg
Results 1 to 7 of 7

Thread: Unable to use changes to My Settings (application.exe.config) file after compilation.

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2019
    Posts
    5

    Unable to use changes to My Settings (application.exe.config) file after compilation.

    Hi all,

    First post so please be patient!

    In VB.net 2013 Professional, I have created a settings file for my OCX <application.exe.config> which is accessed via My.Settings. The settings file contains a list of values which is used to populate a combo box at runtime. The list might change over time so an admin should be able to modify the settings file as they need to. I have compiled the DLL and registered it successfully. The list populates as expected, however when I add one item to the list in the settings file, it is not picked up at runtime. The original list remains. I can't figure out why this is. The only way I can update the list is to do it in Visual Studio - Project->Properties->Settings and then recompile the DLL.

    I have tried changing the compilation configuration from Debug to Release, and changed the Access Modifier to Public from Friend. Nothing I try makes any difference.

    The code which populates the combo box (works ok):
    Code:
    For Each entry As String In My.Settings.Depts
                    cboDept.Items.Add(entry)
    Next
    cboDept.SelectedIndex = 0 'select first item in dropdown list
    An excerpt of my settings file:
    Code:
    <applicationSettings>
          <My.MySettings>
            <setting name="Depts" serializeAs="Xml">
              <value>
                <ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xmlns:xsd="http://www.w3.org/2001/XMLSchema">
                  <string>DeptA</string>
                  <string>DeptB</string>
                  <string>DeptC</string>
                  <string>DeptD</string>
                </ArrayOfString>
              </value>
            </setting>
        </My.MySettings>
    </applicationSettings>
    I should be able to add a DeptE in the list in the settings file and have that appear in the dropdown list, shouldn't I?

    Many thanks in advance!

  2. #2
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    5,338

    Re: Unable to use changes to My Settings (application.exe.config) file after compilat

    I don't think that is the way it works.
    Settings are specific to the user, and to where the user runs the code from.
    The values you add in the IDE are the default, and when a user runs the application for the first time from a given location, a settings file with the default settings is created for that user. If the application is copied to a different directory and run, that is a "different" executable, so another settings file for that user is created with the default values. If the user changes settings while in the program, i.e. the program allows the values to be changed, then the file is updated so that when that user starts that program from that particular directory, then they have the same values they had when they exited the program the last time they ran it.

    The purpose of My.Settings is that it is MY settings, not yours, or some other user. Now, if you run the program and change settings, you should be able to search and find where your settings file is, and you could modify it directly, but of course that is not system wide so won't affect the program if a different user runs it.

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2019
    Posts
    5

    Re: Unable to use changes to My Settings (application.exe.config) file after compilat

    Hi Passel,
    Thanks for your response. I should have said that the scope I've set in the Settings dialog in Visual Studio is Application (as opposed to User) because I don't want the user to be able to change the settings via the application. The contents of the dropdown list should only be updated by a system administrator.

    According to this link:
    https://docs.microsoft.com/en-us/dot...ettings-object
    Scope indicates if the property is read-only. If the value is Application, the property is read-only; if the value is User, the property is read-write.

    The application in question can be run by any user who logs into the system. It is always run from the same location: C:\Program Files (x86)\<program name>\bin.

    Is there a user-specific settings file, and if so, where would I find it?

    Many thanks!

  4. #4

    Thread Starter
    New Member
    Join Date
    Aug 2019
    Posts
    5

    Re: Unable to use changes to My Settings (application.exe.config) file after compilat

    Hi Passel,
    Thanks for your response. I should have said that the scope I've set in the Settings dialog in Visual Studio is Application (as opposed to User) because I don't want the user to be able to change the settings via the application. The contents of the dropdown list should only be updated by a system administrator.

    According to this link:
    https://docs.microsoft.com/en-us/dot...ettings-object
    Scope indicates if the property is read-only. If the value is Application, the property is read-only; if the value is User, the property is read-write.

    The application in question can be run by any user who logs into the system. It is always run from the same location: C:\Program Files (x86)\<program name>\bin.

    Is there a user-specific settings file, and if so, where would I find it?

    Many thanks!

  5. #5
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    5,338

    Re: Unable to use changes to My Settings (application.exe.config) file after compilat

    Well, I don't know if because it is a dll that makes a difference or not. I don't usually compile dlls so don't have a lot of experience with them.
    But, if I compile a standard executable the code seems to work as expected.

    I just did a quick test with a single combobox on a form (and a button).
    I defined the Depts setting as you had with the four departments and built the executable
    Code:
    Public Class Form1
     
      Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        For Each entry As String In My.Settings.Depts
          cboDept.Items.Add(entry)
        Next
        cboDept.SelectedIndex = 0 'select first item in dropdown list
      End Sub
    
    End Class
    The executable's name was AppSettingsTest.exe
    So, I copied the AppSettingsTest.exe file and the AppSettingsTest.exe.config files from the bin directory over to some arbitrary temporary directory.
    I ran it and it worked fine.
    I then changed the config file, changing "DeptA" to "DeptA1" and adding "DeptE" to the list.
    I ran the program again, and the first item in the combobox now showed DeptA1 and pulling down the list showed DeptE at the end of the list.

    I don't know what your problem can be.

  6. #6

    Thread Starter
    New Member
    Join Date
    Aug 2019
    Posts
    5

    Re: Unable to use changes to My Settings (application.exe.config) file after compilat

    Hi Passel,
    Problem solved - I discovered that the Root Namespace in Visual Studio -> Project Properties was blank. Putting the correct value there makes the application work as it should.
    Thanks for your time!

  7. #7

    Thread Starter
    New Member
    Join Date
    Aug 2019
    Posts
    5

    Re: Unable to use changes to My Settings (application.exe.config) file after compilat

    Hi Passel,
    Problem solved - I discovered that the Root Namespace in Visual Studio -> Project Properties was blank. Putting the correct value there makes the application work as it should.
    Thanks for your time!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width