DLL Config File

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hi,

can a DLL use app.config file just like ASP.NET application ? or any idea
how to make DLL is configurable, let say for connection string configuration
may be

Hendri
 
Hi Hendri,

Yes it is possible to use a configuration/xml file for your DLL.

The simplest way of course is to create your own xml file and read from
that. The xml file would have your own custom format specific to that DLL.
The other way involves a bit more work, and you can read up on it here:

http://www.codeproject.com/dotnet/DLLAPPCONFIG.asp

HTH
Altaf
 
S.M. Altaf said:
Yes it is possible to use a configuration/xml file for your DLL.

Hmmm, no it isn't, with the exception of the hack below
The simplest way of course is to create your own xml file and read
from that. The xml file would have your own custom format specific
to that DLL.

Yes that is true, but as you note it is configuration for the library's
*own types* only. The configuration file for an application is more than
just <appSettings> (and config sections) the majority of the file is for
settings used by the framework library classes. So if, for example, you
want to change the list of trace listeners used by types in a library
you have to use the application configuration file. Unless...
The other way involves a bit more work, and you can read
up on it here:
http://www.codeproject.com/dotnet/DLLAPPCONFIG.asp

.... you do this hack. I quite like it actually, but it is in no way
supported by Microsoft. Just to explain, this page shows how you can
change the name of the config file that the application domain reads,
and how to tell the appdomain to junk the current configuration settings
it has read and hence read the new configuration file the next time
config data is requested.

This is different to the suggestion above because when framework library
classes ask for configuration, they will use the values from the cached
hashtable that has been updated. However, note that these new
configuration settings will only be read when those classes read the
data, which they may not do. For example, the list of trace listeners
will be created from the list given in the config file when the
appdomain is created, and the config will never be consulted again
during the lifetime of the appdomain.

IMO this is a weakness of the whole config system in .NET, Microsoft
have cached it all in memory, so there is no 'dynamic-ness' as there is
with the registry.

Richard
 
Back
Top