Settings in App.config of DLL lib used if application
If you are using Settings (Default settings) in your library project you can setup settings section in App.config of application which uses your lib.
Normally you obtain error like Unrecognized configuration section applicationSettings.
You can fix this by merging App.config for dll to App.config of your application.
Pokud máte v dll použité nastavení (Settings) pro aplikaci, tak toto nastavení nemůžete jednoduše nastavit v aplikaci, ve které dané dll používáte. V aplikaci dostanete hlášku, že nastavení nemohlo načteno či „Konfigurační oddíl applicationSettings/MojeAplikace.Properties.Settings nebyl rozpoznán.“
Toto lze obejít změnou v App.config aplikace tak, že do nastavení přidáte sekce settings a zároveň na ně uvedete referenci.
Example
DLL
<?xml version="1.0" encoding="utf-8"?> <configuration> <configSections> <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" > <section name="MojeDLL.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/> </sectionGroup> </configSections> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/> </startup> <applicationSettings> <MojeDLL.Properties.Settings> <setting name="SluzbaURL" serializeAs="String"> <value>https://server:1223/</value> </setting> </MojeDLL.Properties.Settings> </applicationSettings> </configuration>
Aplikace
<?xml version="1.0" encoding="utf-8"?> <configuration> <configSections> <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" > <section name="MojeAplikace.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> </sectionGroup> </configSections> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/> </startup> <applicationSettings> <MojeAplikace.Properties.Settings> <setting name="nejakeNastaveni" serializeAs="String"> <value>hodnota</value> </setting> </MojeAplikace.Properties.Settings> </applicationSettings> </configuration>
App.config after merge
<?xml version="1.0" encoding="utf-8"?> <configuration> <configSections> <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" > <section name="MojeAplikace.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> <section name="MojeDLL.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/> </sectionGroup> </configSections> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/> </startup> <applicationSettings> <MojeAplikace.Properties.Settings> <setting name="nejakeNastaveni" serializeAs="String"> <value>hodnota</value> </setting> </MojeAplikace.Properties.Settings> <MojeDLL.Properties.Settings> <setting name="SluzbaURL" serializeAs="String"> <value>https://server:1223/</value> </setting> </MojeDLL.Properties.Settings> </applicationSettings> </configuration>