Locating config file from .dll in both Desktop and Web applications

I’m using Nini for most my config needs. Nini is a .Net library for reading/writing/merging all kinds of config files. It provides a good API with type conversion, default values, etc.

To be able to access both app.config and web.config using Nini in .dll files included in test projects, desktop applications, services, web applications, webservices, etc I’ve put together a small method that automatically resolves current application configuration file by checking if it is running under web or not and resolving the correct directory+file. It also caches the response to save a few CPU cycles.

Example use with Nini

Source code for resolving config file

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: