Tedd Hansen
Tedd Hansen

Reputation: 12314

Finding app config file from assembly

I'm using Nini to read config throughout the app. I'm running into a problem in assemblies where I want to read the main applications config file (regardless of web.config or app.config).

This is standard way:

private static IConfigSource source = new DotNetConfigSource(DotNetConfigSource.GetFullConfigPath());

The problem in the case of assemblies is that DotNetConfigSource.GetFullConfigPath() returns "assembly.dll.config", not "app.exe.config" or "web.config".

What to do, what to do?

Upvotes: 0

Views: 220

Answers (1)

jaywayco
jaywayco

Reputation: 6286

System.Configuration.Configuration config =
                ConfigurationManager.OpenExeConfiguration(
                ConfigurationUserLevel.None);

string configPath = config.FilePath;

private static IConfigSource source = new DotNetConfigSource(configPath);

Try that.

Upvotes: 1

Related Questions