DLL Config Files

D

Doug

I've seen some info on this out here but nothing that I could find and
try worked for me.

I have a DLL that I want to have a config file for. As is probably
well known, the application that calls that DLL cannot read my config
file. Is there no way to accomplish this?

I've tried creating a DLLName.dll.config file and placing it in the
same folder my exe and dll are in and it still doesn't work.
 
B

Brian Gideon

Doug,

What I have done in the past is to have the dll read a custom
configuration section in the main app.config file. I'm not saying that
it is the best solution, but personally I think it's easier than having
one file per dll for a couple of reasons. 1) There's only one file
that contains all of your application's configuration. I dislike
having my application's configuration scattered all over the place.
Invariably I make a change in one location and forget to do it in
another. 2) The ConfigurationSettings.GetConfig method can be used to
access the custom configuration section so there's no need to code your
own reader. This can be called from code within your dll and will work
the same as calling it from the main application's exe.

Brian
 
D

Doug

The only thing I can see that would hinder me on, is that I'd like to
make my DLL common enough to be used by other applications. If I
understood your solution, my DLL would have to know what app is calling
it, right?

I'm trying to find a way to have the DLL have config information that
the app knows nothing about. I am thinking my only option is to just
to code it to read a specific file of my choosing, instead of using the
app.config file.

I'm confused as to why DLL.Config files are even possible if they can't
be used? Seems odd.
 
B

Brian Gideon

Doug said:
The only thing I can see that would hinder me on, is that I'd like to
make my DLL common enough to be used by other applications. If I
understood your solution, my DLL would have to know what app is calling
it, right?

No. The dll would not have to know what app is calling it. Slightly
off topic...but you can get get the calling application by using
Assembly.GetEntryAssembly(). Anyway, if you call
ConfigurationSettings.GetConfig() it automatically reads from the main
app.config file no matter where in code it is called from. That
includes calling it from a dll.
I'm trying to find a way to have the DLL have config information that
the app knows nothing about. I am thinking my only option is to just
to code it to read a specific file of my choosing, instead of using the
app.config file.

Of course, using this approach the application's app.config would have
to contain the configuration for the dll. I don't really see that as a
problem unless your dll is designed to be dynamically loaded by the
application. If it's referenced by the application at compile time
then the application already knows about the dll so there's no reason
you can't setup the app.config correctly.
 

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