Short version:
I’m making a DLL that I intend to pass around the department, and it requires certain values to be present in the web.config of the app that references it. Is there any way to make my DLL check for these values before run time?
Long version, with background info:
We’re using website-level web.config files to configure environment information for multiple websites/WCF services on the same server. When developing these apps, I have the debug versions of the web.config insert test values, and all is well. However, I’d like to reduce the hidden requirement as much as possible for future users [me, in a year, when I forget all this] and make missing config settings as obvious as possible. If a reference or build time solution is impossible or unfeasible, what’s the earliest run-time opportunity my DLL can hook into to check its configuration?
Also- we’re using the built-in application configuration classes to decrypt settings automatically at run time, as well as taking advantage of the configuration hierarchy, so we’re locked into using app/web.config files. If anyone knows a more solid way of designing the system with regards to referenced assemblies requiring configuration entries, I would appreciate suggestions.
There is no real
Mainequivalent for a DLL. The best option is to guard all of your DLL entry points with the method that will validate the configuration (and presumably cache the result).Unfortunately depending on the contents of your DLL this can be quite time consuming. The best way to start is looking at all of the
publictypes and static methods. These are your most obvious entry points to the code base.This may also be a good time to review your entry points and limit them to a managable level 🙂