How to refresh applicationSettings in a dll
Can i force开发者_开发知识库 a dll to reload it's configuration?
In my VB library I'm using this configuration:
<applicationSettings>
<ComWrapper.My.MySettings>
<setting name="MySetting" serializeAs="String">
<value>This is an entry</value>
</setting>
</applicationSettings>
It's no problem to access the "MySetting" value from the code:
Public Function GetSetting() As String
Return ComWrapper.My.MySettings.Default.MySetting
End Function
but it look like that the value "This is an entry" is embedded into the dll's code. If I change it in the app.config or in the ComWrapper.dll.config file it has no effect on the return value.
The configurations values are taken from the executing process configuration. Means, If you have ComWrapper.dll and its config file, runing under the context of YourProcess.exe, the configuration settings will be taken from YourProcess.exe.config.
So, you need to insert the ComWrapper settings to the YourProcess.exe.config file, otherwise the default generated value (you can find it in the Settings.Designer file).
I've found the solution by myself
AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", filename)
It's safe for me because I'm calling my lib out of Excel, so i won't overwrite foreign config values.
I've solved my problem doing this:
ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
fileMap.ExeConfigFilename = Assembly.GetExecutingAssembly().Location + ".config";
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
string value = config.AppSettings.Settings["X"].Value
精彩评论