J'ai un addin .NET personnalisé pour une application et j'essaye de créer des configSections pour le fichier de configuration de l'addin. Le problème est que je ne suis pas capable de lire cette section Si charger la configuration en utilisant OpenMapperExeConfiguration/OpenExeConfiguration.Est-il possible de définir <configSections> dans la configuration de l'application d'une DLL dépendante?
Voici mon fichier de configuration (MyTest.dll.config)
<configuration>
<configSections>
<section name="test" type="MyTest, Test.ConfigRead"/>
</configSections>
<test>
..Stuff here
</test>
<appSettings>
<add key="uri" value="www.cnn.com"/>
</appSettings>
</configuration>
Voici mon exemple de code pour accéder au configSection test
ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
fileMap.ExeConfigFilename = Assembly.GetExecutingAssembly().Location + "config";
Configuration applicationConfig = ConfigurationManager.OpenMappedExeConfiguration(fileMap,ConfigurationUserLevel.None);
//Using OpenExeConfiguration doesnt help either.
//Configuration applicationConfig = ConfigurationManager.OpenExeConfiguration(Assembly.GetExecutingAssembly().Location);
//Accessing test section
applicationConfig.GetSection("test");
//Accessing AppSettings works fine.
AppSettingsSection appSettings = (AppSettingsSection)applicationConfig.GetSection("appSettings");
appSettings.Settings["uri"].Value;
Comme le montre la valeur AppSettings peut être lu très bien. Est-il possible d'avoir configSections dans une autre configuration autre que le fichier de configuration de l'application principale?