Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Separate app.config for dll? 1

Status
Not open for further replies.

adam0101

Programmer
Jun 25, 2002
1,952
US
Is it possible to have my assembly read from a config file other than the one used by the application consuming my assembly (without reading it like a regular xml file)? I know in the 1.1 framework you could do this by creating a separate appDomain, but I am hoping that this sort of thing is a little easier in one of the newer frameworks. Can anyone shed some light on this for me?

Thanks,

Adam
 
A well written dll won't need to read from a config file itself. It should require parameters from any config file in order to be created. This way, the end user's app is responsible for passing you the data you need in order to function.

 
No problem. Just copy an app.config from another project. or just create an xml file and name it app.config.

I disagree with JurkMonkey but only a little bit. Some DLL's need a bit of configuration. But perhaps app.config is not the best place to put it. I gave each of my DLL's an app.config for the log4net configuration so that they work seperatly but they can still be overriden by the calling app. Consider it a default configuration.

Christiaan Baes
Belgium

My Blog
"In a system where you can define a factor as part of a third factor, you need another layer to check the main layer in case the second layer is not the base unit." - jrbarnett
 
JurkMonkey said:
A well written dll won't need to read from a config file itself...
Well, here's the scenario... I have an assembly that is called from a modified version of Enterprise Library to perform auditing functions. This assembly is on the Test, UAT, and Production servers. I don't want the developers to have to worry about putting the auditing config settings in each of their apps, or maybe more accurately put, I don't want to have to trust that the developers will configure their apps correctly for auditing. (We've had problems in the past.) However, I still want to be able to have different settings for each environment. I felt that adding the config file to the dll itself would be the best solution.


Chrissie, I have an app.config in my assembly and I see that it's getting renamed to myassembly.dll.config when I compile, but the dll is still grabbing the settings from the app.config of my test app. How do I get it to read from the dll's app.config instead?

Adam
 
Mmm, well that's a good question. I don't use them that often. Like I said I use them as defaults which get override by the calling app. So I'm probably using them the way MS wants them to be used. Mind you I don't use them a lot just for configuring log4net.

After some research. It seems possible.


and

(see comments)

But I would not recommend it. And it would use the seperate AppDomain again.

Christiaan Baes
Belgium

My Blog
"In a system where you can define a factor as part of a third factor, you need another layer to check the main layer in case the second layer is not the base unit." - jrbarnett
 
It doesn't appear that the dll is reading the config file for default values either. It seems to be completely ignoring it. I must be doing something wrong.

Thanks for the links.

Adam
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top