How can I refer to configuration information from multiple class libraries?

I have a bunch of DLL projects that I pull into my application, each of which contains its own parameter Settings.settings / app.config. When I compile the application and run for debugging, everything works fine, but it's time to deploy. I cannot get my DLLs to read my own settings files.

I read several times, and it became obvious that there are several ways to make each dll read its own configuration - one is to dedicate the .dll.config library to the library, and the other to embed the dll in the process.exe.config file.

I am having significant problems trying to implement them, and I wondered if anyone has any good documents on this subject - they’re missing on the Web.

I need a separate .dll.config for each of the libraries, if possible, but in the worst case, so that each of my libraries read their own section process.exe.config.

Can someone point me in the right direction, because I'm so close to rolling this application, but this stumbling block causes me a significant headache.

Edit: When I merge configuration files, I start getting TypeInitializer exceptions when I initialize the objects associated with my libraries. Most likely it’s delaying me, but does anyone have a working example of a merged configuration file and some basic demo code for reading it from several assemblies?

+3
source share
3 answers

" ", ? dll exe, , . dll. , , ( ) , , .

app.config, :

  <?xml version="1.0" encoding="utf-8" ?>
  <configuration>
    <configSections>
      <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
        <section name="SharedConfig.Client.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
        <!-- Begin copy from library app.config -->
        <section name="SharedConfig.Library.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
        <!-- End copy from library app.config -->
      </sectionGroup>
    </configSections>
    <applicationSettings>
      <SharedConfig.Client.Properties.Settings>
        <setting name="Bar" serializeAs="String">
          <value>BarFromClient</value>
        </setting>
      </SharedConfig.Client.Properties.Settings>
      <!-- Begin copy from library app.config -->
      <SharedConfig.Library.Properties.Settings>
        <setting name="Bar" serializeAs="String">
          <value>BarFromLibrary</value>
        </setting>
      </SharedConfig.Library.Properties.Settings>
      <!-- End copy from library app.config -->
    </applicationSettings>
  </configuration>
+2

ConfigurationSection.

process.exe.config.

MSDN VB, #.

0

. app.config DLL " " ... WCF DLL?. - " ". , Microsoft . .NET 2.0, DLL. DLL - .exe.config.

0

Source: https://habr.com/ru/post/1704717/


All Articles