Config File .dll


G

Guest

Hello All:

When you develop a C# app that is deployed as an .exe, you can use a
[appname].exe.config file to set some parameters to avoid changing code.

I would like to do the same thing using a .dll, however: I am not sure how
to go about doing this with a .dll, as the config file does not have a unique
name. Is there something special you have to do? Is it possible? Worst
case scenerio would be we pass into the dll (maybe as part of the
constructor) the parameter we would like set, however: the prefered method
is a config file is possible. Any help / examples would be greatly
appreciated.

Thanks
Andy
 
Ad

Advertisements

G

gyurisc

the config file is per appdomain, so when you have the dll running it would
be loaded into an appdomain and the appdomain's config file will be used for
the dll as well. let's say you are doing a managed plugin for excel.exe,
then your plugin's config will be called excel.exe.config. You may just want
to pass the config object to your dll and see if there is something specific
for your dll.

Hope this helps.
 
D

Dan Bass

The approach I would take in this situation would be to pass any
configuration data required by the library into it when it is called. ou
could, for example, initialise the object by passing in parameters with the
constructor that initialises that instance of the class.

The configuration could then be read by the application, and fed through to
any appropriate objects as required.

Generally, it's good practice to keep libraries modular. This means not
having them depend on their surroundings (location or neighbouring files) in
order to work correctly when called by an application.
 
Ad

Advertisements

G

Glenn

Andy


It may not be the best way, but, in the past I've created XSD schema
definitions and then from those used the xsd.exe tool to create serialisable
types representing the configuration information required for the DLL. You
need to remember to move the XML configuration file with the DLL when you
reference it, but even if you don't it'll soon let you know it's missing.



The nice thing about it is if your using VS.NET, when you create your
configuration file, simply set the targetSchema to that of the XSD and
you've got intellisense (watch your elements though, VS displays them
alphabetically not in the sequence specified in the schema). In addition,
you can validate the XML configuration file prior to deserialisation. In
some instances this may be a little too anally retentive, but sometimes you
do want to check values fall within a particular range, etc., at which time
it proves very useful.



Another nice thing about it is that your configuration properties in the
deserialised type will be available in intellisense, so no key value pairs.
Not much of an advantage, but it's something.



Little code snippet....

XmlSerializer deserialiser = new XmlSerializer(
typeof(MyConfigurationType), "http://www.afcb.co.uk/PlayerConfiguration" );

using ( FileStream stream = File.Open( ConfigurationXmlPath, FileMode.Open,
FileAccess.Read ) )
{
_myConfiguration = deserialiser.Deserialize( stream ) as
MyConfigurationType;
}

HTH

Glenn
 

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

Similar Threads

Config files for dll's 2
Config File and dll 0
Reading a config file from a .DLL 1
DLL and Application Config 1
Config Files 2
Config files 2
config file 1
Config file 2

Top