Get A DLL’s Configuration Settings From The Calling Applications App.Config File.

Posted on Updated on

I had this problem recently, how do i read a dll’s configuration from the calling applications app.config file? It turns out to be quite easy, Just copy the .dll section from its app.config.

<section name="somedll.Properties.Settings"  type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowexedefinition="MachineToLocalUser" requirepermission="false"></section>

Then paste it into the the calling applications app config.
section.

 <configSections>
        <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
            <section name="someApp.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
            <section name="somedll.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
        </sectionGroup>
        <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
            <section name="someApp.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
        </sectionGroup>
    </configSections>

Then copy the setting from the dll’s such as its connection string and paste it into the

<connectionStrings>

section.Then your are done, now when your run the application the loaded dll will read its configuration from the calling applications app.config file.

Advertisements

One thought on “Get A DLL’s Configuration Settings From The Calling Applications App.Config File.

    wizzla said:
    November 12, 2011 at 3:17 pm

    Nice…. good one!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s