Bluephlame
Bluephlame

Reputation: 3969

How do you load the app.config file into a DLL

So I cant find a definitive answer to the Question. How do you load the app.config file into a DLL.

I understand that generally the App.config info should be put into the executable app.config. However i am building an add-in and have to executable available.

I would like to use the namespace.dll.config file to store my variables, but i need a way of loading it into the system.

Do you need to build out some code to load this file in?
Can you use the configurationManager namespace to make this happen easily?

Upvotes: 3

Views: 3505

Answers (2)

John Saunders
John Saunders

Reputation: 161821

The way this is done is that you should supply your assembly.dll.config to consumers of your assembly. They should then incorporate those entries into their application's config file.

Your assembly will then be able to access those values through normal means.

Upvotes: 2

Lachlan Roche
Lachlan Roche

Reputation: 25956

This example will load any *.config file from your bin directory as a new configuration object.

Alternatively, .NET Settings will automatically compile the default into the assembly.

public Configuration DllConfiguration( string filename )
{
    var map = new ExeConfigurationFileMap {
         ExeConfigFilename = Path.Combine( AppDomain.CurrentDomain.BaseDirectory, filename )
    };

    return ConfigurationManager.OpenMappedExeConfiguration( map, ConfigurationUserLevel.None );
}

Upvotes: 2

Related Questions