none
Multiple Settings files RRS feed

  • Question

  • I have windows service that i developed a UI for to managing the service and viewing custom log data. I created a settings class library that has 4 different settings files, DEV, STAGE, Beta, Release. I have a class within the class library that use compiler directives for each configuration that i compile it into. I use the UI for changing settings which works great with the UI but when the service starts, it gets the default values from the settings file related to the build instead of the saved values that i had changed. This is a property from my settings class. This is how i set values and read them. Reading the save values through the UI works like its supposed to, but it doesn't work like that when the windows service reads those same settings through the class. Is there a way to get the saved values? Any help is greatly appreciated.

        Public Property AutoExecute As Boolean
            Get
                Try
    #If DEV Then
                    m_AutoExecute = DEVSettings.Default.AutoExecute
    #ElseIf UAT Then
                    m_AutoExecute = UATSettings.Default.AutoExecute
    #ElseIf BETA Then
                    m_AutoExecute = BETASettings.Default.AutoExecute
    #Else
                    m_AutoExecute = MySettings.Default.AutoExecute
    #End If
                Catch ex As Exception
                    m_AutoExecute = False
                End Try
                Return m_AutoExecute
            End Get
            Set(ByVal value As Boolean)
    #If DEV Then
                DEVSettings.Default.AutoExecute = value
    #ElseIf UAT Then
                UATSettings.Default.AutoExecute = value
    #ElseIf BETA Then
                BETASettings.Default.AutoExecute = value
    #Else
                MySettings.Default.AutoExecute = value
    #End If
                m_AutoExecute = value
            End Set
        End Property

    Friday, March 1, 2019 9:04 PM

All replies

  • Maybe your service should not have compiler directives. It will always load the settings from the default file (MySettings.Default).

    But the UI will have several files. When you select the active configuration to be used, it will also replace the default configuration file that is used by service. (Or you can copy and rename the file manually).

    • Edited by Viorel_MVP Saturday, March 2, 2019 7:33 AM
    Saturday, March 2, 2019 7:32 AM
  • The compiler directives are in the class that I use to read/write settings. The service reads the proper default settings fine for the configuration that I compile to but doesn't read the saved values if I change them through the UI. However; I can't seem to find the default settings file for the service after its installed. Its reading it from somewhere because its not reading it from the appdata/local folder that the saved values go to. This is the save method I have in my class.

        Public Sub Save()
    #If DEV Then
            DEVSettings.Default.Save()
    #ElseIf UAT Then
            UATSettings.Default.Save()
    #ElseIf BETA Then
            BETASettings.Default.Save()
    #Else
            MySettings.Default.Save()
    #End If
    
        End Sub

    I don't have any settings created in the service itself, I have them in a "settings" class that I created and have in a separate class library. I did have a custom class that I created that actually saves the values to an XML file for the user into %userprofile%/appdata/local but I was experiencing issues with windows security because of network policies in some cases and different users logging into the server and running the UI for the service and it trying to read settings based on their user login. I wanted to find a better solution. This seemed to be the ideal thing but isn't working out the way I thought it would. It does work great for an app with a UI though. All the .settings files are in my class library. Shouldn't this work for a class library as well?


    Saturday, March 2, 2019 4:41 PM
  • Hi,

    Welcome to MSDN forum.

    This forum is discussing Visual Studio WPF/SL Designer, Visual Studio Guidance Automation Toolkit, Developer Documentation and Help System, and Visual Studio Editor. I will move your case to VB forum to seek for better support.

    Best regards,

    Joyce


    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 MSDNFSF@microsoft.com.

    Monday, March 4, 2019 7:27 AM