views:

122

answers:

3

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.

+2  A: 

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).

sagie
+1, complete explanation
Rubens Farias
Thanks. I will look for another solution like loading the app.config, because the application executing my lib is Excel.
alex
A: 

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.

alex
A: 

Sorry, im lost. What do you do then?

Thanks.

-Update-

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
Morvader
I thought that was the trick. Sorry but I can't check out for a couple of days.
alex