How to update applicationSettings in dll

Can I force a DLL to reload its configuration?

In my VB library, I use this configuration:

<applicationSettings>
    <ComWrapper.My.MySettings>
        <setting name="MySetting" serializeAs="String">
            <value>This is an entry</value>
        </setting>
</applicationSettings>

Unable to access "MySetting" value from code:

Public Function GetSetting() As String
    Return ComWrapper.My.MySettings.Default.MySetting
End Function

but it looks like the value "This entry" is embedded in the dll code. If I change it in app.config or in ComWrapper.dll.config file, it will not affect the return value.

+3
source share
3 answers

The configuration values ​​are taken from the configuration of the executable process. So, if you have ComWrapper.dll and its configuration file, launched in the context of YourProcess.exe, the configuration settings will be taken from the file YourProcess.exe.config.

, ComWrapper YourProcess.exe.config, ( Settings.Designer).

+2

AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", filename)

, lib Excel, .

0

I decided to solve this problem:

ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
fileMap.ExeConfigFilename = Assembly.GetExecutingAssembly().Location + ".config";

Configuration config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);

string value = config.AppSettings.Settings["X"].Value
0
source

Source: https://habr.com/ru/post/1729211/


All Articles