I've deployed an Outlook2007Addin and I've noticed in testing that changes I make to my app.config are not recognized. That is, I edit MyOutlookAddInName.dll.config in the install directory, save changes, and then bring up Outlook.
My addin behaves properly except for the fact that the changed values are ignored. Instead it operates with the "original" values. How can I make this addin responsive to changes in the dll.config immediately?
Here is a snippet from my initialization code and I've verified with debugger that values are indeed fetched from app.config:
private string _TRIM_archiveFolderName = "TRIM Archives";
private string _specialFolder = @"\INBOX\TRIM\"; // eg. \INBOX\TRIM makes a big difference
private string saveAttachments = "Yes";
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
log.Info("Application Start");
try
{
_TRIM_archiveFolderName = Properties.Settings.Default.TRIM_ArchiveFolderName;
_specialFolder = Properties.Settings.Default.TRIM_Upload_INBOX_Path;
saveAttachments = Properties.Settings.Default.SaveAttachments;
}
catch (Exception ex)
{
log.Warn("App.Config error detected and ignored",ex);
}
Here is the XML view of the Settings.settings file in my Visual Studio project:
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="CBMI.Outlook2007AddInV7.Properties" GeneratedClassName="Settings">
<Profiles />
<Settings>
<Setting Name="TRIM_ArchiveFolderName" Type="System.String" Scope="Application">
<Value Profile="(Default)">TRIM Archives</Value>
</Setting>
<Setting Name="TRIM_Upload_INBOX_Path" Type="System.String" Scope="Application">
<Value Profile="(Default)">\INBOX\TRIM\</Value>
</Setting>
<Setting Name="SaveAttachments" Type="System.String" Scope="Application">
<Value Profile="(Default)">Yes</Value>
</Setting>
<Setting Name="TRIMconnectionParms" Type="System.String" Scope="Application">
<Value Profile="(Default)">60~GROUPER~1137</Value>
</Setting>
</Settings>
</SettingsFile>
Here is how my dll.config looks in the install directory (before I changed it and saved changes):
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings"
type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="CBMI.Outlook2007AddInV7.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<section name="FileServiceProxy.Properties.Settings"
type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
requirePermission="false" />
</sectionGroup>
</configSections>
<applicationSettings>
<CBMI.Outlook2007AddInV7.Properties.Settings>
<setting name="TRIM_ArchiveFolderName" serializeAs="String">
<value>TRIMArchives</value>
</setting>
<setting name="TRIM_Upload_INBOX_Path" serializeAs="String">
<value>\INBOX\TRIM\</value>
</setting>
<setting name="SaveAttachments" serializeAs="String">
<value>Yes</value>
</setting>
<setting name="TRIMconnectionParms" serializeAs="String">
<value>60~GROUPER~1137</value>
</setting>
</CBMI.Outlook2007AddInV7.Properties.Settings>
<FileServiceProxy.Properties.Settings>
<setting name="FileServiceProxy_ASMXproxy_FileService" serializeAs="String">
<value>http://mdwdata/sdkTrimFileServiceASMX/fileservice.asmx</value>
</setting>
</FileServiceProxy.Properties.Settings>
</applicationSettings>
There may be other approaches to resolve this. However, I opened this thread on MSDN and someone helped me by suggesting the ConfigurationManager.RefreshSection method. See:
http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/d8104247-3609-42f7-8e06-71860f3f81e2