By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,419 Members | 1,371 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,419 IT Pros & Developers. It's quick & easy.

Config File .dll

P: n/a
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
Nov 16 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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.
"Andy" <An**@discussions.microsoft.com> wrote in message
news:AB**********************************@microsof t.com...
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

Nov 16 '05 #2

P: n/a
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.

"Andy" <An**@discussions.microsoft.com> wrote in message
news:AB**********************************@microsof t.com...
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

Nov 16 '05 #3

P: n/a
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

"Andy" <An**@discussions.microsoft.com> wrote in message
news:AB**********************************@microsof t.com...
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

Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.