How to tell C# which config file to use? [duplicate]
Possible Duplicate:
Reading dll.config (not app.config!) from a plugin module.
I have two different projects, say A and B. I need to use some classes of A in B. So I added a reference to A in B. When I tried to run the applicat开发者_运维百科ion, I stated getting Object reference set to null exception. On investigation, I found that when I access classes of A from B, control goes to project A, but C# still uses config file of project B instead of using project A's config file. How do I get around this? How can I "include" A's config file in the dll?
I have gone through this blog but I feel it is a very dirty way of doing it. There ought to be an easier way!
Let me know if the question is unclear..
I believe .NET will always load the app.config file associated with the application rather than any libraries. There are complicated ways of specifying your own locations for config files - or just using your own configuration framework instead of the built-in one - but I don't think you can just ask .NET to load a config file per DLL.
Why don't you just all the necessary settings into the config file from project B? If you use some tools and libraries from an external vendor you just do the same stuff to configure it.
If you abstracted the configuration good enough you should be fine. Using another configuration file than the default one - well i would consider this as bad practice.
As I understand this you want integrate a app.config into your dll. Check this out:
How do you load the app.config file into a DLL
You can copy the relevant sections of A's config into the B config file and it'll work properly, but it's a bit tedious to say the least. I suppose you could automate it with a custom tool though.
精彩评论