DLL settings in Application settings file

S

Sid Price

Can someone point me in the right direction with VB.NET 2005 to be able to
have a class library save settings in the hosting application config file. I
have searched but been unable to discover a solution,
Thanks,
Sid
 
C

Cor Ligthert[MVP]

AFAIK is this impossible you have to set the attributes above (including in)
the class declaration or the methods.

Cor
 
S

Sid Price

Steve Gerrard said:
There are several reasons why this might be difficult. How does a dll even
know whether the host application has a config file? It could be used by
several different apps, one a web app, another a windows app, another a
windows service.
I agree that if this were a class library being offerd for sale that this
could be an issue. However this is a class library designed ot be used by a
suite of applications designed and written for a specific applications
within a company.
A more typical approach would be to put methods in the DLL for setting
various things from the host application. The host app might get them from
a config file, or maybe from a database, or may just hard code them in,
for that matter. If there is something useful to save from the DLL, the
host app can retrieve those values, through properties, or a list, and
save them somewhere for future use if it feels like it - or not.
Again I agree basically with your point here; however there are some aspects
of the configuration of the class library that the host application does not
need to be burdoned with setting and saving. If one is writing a well
encapsulated object for use by client applications then there could well be
some configuration a host application should not have to concern itself
with. As an example, this class library initially uses a TCP/IP connection
to a server to aquire data on behalf of the host application. The IP address
and port need to be configured for this; however a future release of the
class library may make use of a different connection technology (say named
pipes). It is our goal that the host application should not have to be
modified in order to use the changed class library.

I found the following code that is supposed to gain access to the settings
of a DLL's host application settings file but it does not appear to work.
The "sectGroup" variable is set to "nothing". Can anyone see why this might
not work?

Dim exeConfig As Configuration

exeConfig =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)

Dim sectGroup As ApplicationSettingsGroup

sectGroup = exeConfig.GetSectionGroup("applicationSettings")

If sectGroup Is Nothing = False Then

Dim sect As ClientSettingsSection

sect = sectGroup.Sections("MyApp.My.MySettings")

Dim elm As SettingElement

elm = sect.Settings.Get("MySetting")

Dim strXml As String = elm.Value.ValueXml.InnerXml

End If

Thanks,

Sid.

A dll cannot really tell the host app what to do.
The class library does not do that; nor should correct operation of the
class library be dependent upon the host providing validated configuration
parameters ... hence my question.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top