0

I am developing a plugin for a .NET 4 application and I want to add a config file to the dll as I dont want to put the configuration in the main config file. I have added the app.config t the project and it is correctly compile and dllName.dll.config generated.

Here is my configuration file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="MyTabsConfig" type="NewApp.UI.MyTabsConfigHandler, NewApp.UI" />
  </configSections>
  <MyTabsConfig>
    <MyTabs>
      <MyTab Name="First" Leads="2" />
      <MyTab Name="Second" Leads="4" />
      <MyTab Name="Third" Leads="1" />
    </MyTabs>
  </MyTabsConfig>
</configuration>

Now I have 1 problems: If I copy the file in the ExtraPlugins directory of my main application, NewApp.UI.dll cannot be found when calling GetSection("MyTabsConfig"). I think it is looking in the main application folder.

Thanks.

Simone
  • 251
  • 2
  • 11

1 Answers1

0

Have you tried something like this?

ConfigurationSection section = ConfigurationManager.OpenExeConfiguration("myConfig.config").GetSection("mySection");
Bartosz Wójtowicz
  • 1,321
  • 10
  • 18
  • Well yes, I do something like that, ConfigurationManager.OpenExeConfiguration gets the configuration file. I get an exception when I call GetSection on it: "Could not load file or assembly 'NewApp.UI' or one of its dependencies. The system cannot find the file specified.":"NewApp.UI"". I think it is looking for this dll in the main folder whle the librariy and its config are in the "ExtraPlugins" directory. – Simone Dec 19 '11 at 10:19
  • Then I would try a relative path if it's know to you. i.e. `OpenExeConfiguration("../ExtraPlugins/myConfig.config")` – Bartosz Wójtowicz Dec 19 '11 at 10:30