Configuratiebestand voor DLL bestanden

Status
Niet open voor verdere reacties.

tuning4you

Gebruiker
Lid geworden
3 jun 2007
Berichten
328
Ik heb een project bestaande uit een class library DLL en een EXE.
Wanneer ik de applicatie EXE run, dan wordt het configuratiebestand van de applicatie gebruikt. Het configuratiebestand van de DLL wordt volledig genegeerd. Als ik daar wijzigingen in aanbreng, dan worden deze niet doorgevoerd in mijn applicatie.

Wat is het beste om configuratiegegevens toch door te geven aan een class library DLL bestand? Al dan niet door een gescheiden configuratiebestand.
 
Kun je op een aantal manieren oplossen; 1 daarvan is als volgt:

[CPP]var appConfig = ConfigurationManager.OpenExeConfiguration(Assembly.GetExecutingAssembly().Location);
string dllConfigData = appConfig.AppSettings.Settings["dllConfigData"].Value;[/CPP]


Hier staat een interessante discussie over dit onderwerp.
 
Bedankt voor uw antwoord maar ik weet niet hoe ik ConfigurationManager kan oproepen. Ik gebruik Visual Basic.

Ik heb echter al een oplossing gevonden die me al kan behelpen.
In mijn app.config pagina voeg ik gewoon onder <configSections> <sectionGroup> een tweede <section name> aan toe, namelijk met de gegevens van mijn DLL bestand.
Onder <applicationSettings> voeg ik de settings van mijn DLL bestand toe. Van zodra ik hieronder een wijziging aanmaak, dan wordt dit aangepast binnen mijn applicatie die gebruik maakt van de DLL. Wanneer ik dit niet doe, dan neemt de applicatie de default settings van de DLL waarmee deze is gecompileerd.



Voorbeeld van mijn applicatie config file. Wat in het rood staat komt uit de config file van mijn DLL die niet werd gebruikt indien je wijzigingen aanbrengt.
<?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="applicatie.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<section name="applicatie.DataAccess.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>


</configSections>
<system.diagnostics>
<sources>
<!-- This section defines the logging configuration for My.Application.Log -->
<source name="DefaultSource" switchName="DefaultSwitch">
<listeners>
<add name="FileLog"/>
<!-- Uncomment the below section to write to the Application Event Log -->
<!--<add name="EventLog"/>-->
</listeners>
</source>
</sources>
<switches>
<add name="DefaultSwitch" value="Information" />
</switches>
<sharedListeners>
<add name="FileLog"
type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"
initializeData="FileLogWriter"/>
<!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log -->
<!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/> -->
</sharedListeners>
</system.diagnostics>
<applicationSettings>
<applicatie.My.MySettings>
<setting name="Startnummer" serializeAs="String">
<value>9801</value>
</setting>
</applicatie.My.MySettings>
<applicatie.DataAccess.My.MySettings>
<setting name="ConnectionString" serializeAs="String">
<value>Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\test.accdb</value>
</setting>
<setting name="KeepConOpen" serializeAs="String">
<value>True</value>
</setting>
</applicatie.DataAccess.My.MySettings>

</applicationSettings>
</configuration>
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan