Strange behaviour of my.settings RRS feed

  • Question

  • I have three settings in my project settings all strings

    DbPassword = 6ZCLcA8cFkPXW2GcpEgWVg==
    Encrypted = 6ZCLcA8cFkPXW2GcpEgWVg==
    Test = 6ZCLcA8cFkPXW2GcpEgWVg==

    However, when I run the application from the IDE and check the value of DbPassword, the value is always different
    In fact it's always CZlNydwMEheWv+8ZKYX6bA==

    The application seems to be remembering this value from earlier. The other ones are correct.
    I've searched the entire project for the string CZlNydwMEheWv+8ZKYX6bA== but it's nowhere to be found.
    I've also run 'Clean' & 'Rebuild' but it makes no difference.

    If I look in the user.config file in AppData\Local\… then sure enough

    <?xml version="1.0" encoding="utf-8"?>
                <setting name="DbPassword" serializeAs="String">

    I guess it must be copying the user settings each time I debug the app. But it is only ever the 1 setting for dbPassword.
    Anyone explain to me what is happening?

    Friday, April 5, 2019 8:19 AM

All replies

  • To see if it's remembering from the user settings folder add a reference to System.Comfiguration then add the following class.

    Imports System.Configuration
    Namespace My
        Partial Class MyApplication
            ''' <summary>
            ''' Returns User.config file folder name
            ''' </summary>
            ''' <value></value>
            ''' <returns></returns>
            ''' <remarks>
            ''' * Folder may not exists if nothing has been saved to the config file.
            ''' * Use UserConfigurationFileFolderExists to see if the folder actually exists.
            ''' + Requires a reference to System.Configuration.dll
            ''' </remarks>
            Public ReadOnly Property UserConfigurationFileFolder() As String
                    Dim config = ConfigurationManager.OpenExeConfiguration(
                    Return config.FilePath.Replace("\user.config", "")
                End Get
            End Property
            Public ReadOnly Property UserConfigurationFileFolderExists() As Boolean
                    Return IO.Directory.Exists(UserConfigurationFileFolder)
                End Get
            End Property
        End Class
    End Namespace

    This will report if the config file exists and provide the path.

    If My.Application.UserConfigurationFileFolderExists Then
        Console.WriteLine("Does not exists")
    End If

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    profile for Karen Payne on Stack Exchange

    Friday, April 5, 2019 9:39 AM
  • Thanks Karen,

    I tried your code and the result is "Does not exist"
    However before I received you reply I published the application with clickonce, just to see if the effect persisted.
    It worked correctly as an installed app.
    This also seemed to fix the problem, and it is now working as expected from the IDE
    So, I don't know what caused that behaviour?

    Friday, April 5, 2019 11:52 AM
  • Hi,

    You can try to look at the .exe.config file in the bin folder and see if the value inside is the one you need.If not, you can fix it before running.

    Best Regards,


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Tuesday, April 9, 2019 5:40 AM