Equivalent to 'app.config' for a library (DLL)

equivalent synonyms
equivalent definition math
equivalent to something
equivalent antonym
equivalent verb
equivalent to symbol
equivalence
how to pronounce equivalent

Is there an equivalent to app.config for libraries (DLLs)? If not, what is the easiest way to store configuration settings that are specific to a library? Please consider that the library might be used in different applications.

You can have separate configuration file, but you'll have to read it "manually", the ConfigurationManager.AppSettings["key"] will read only the config of the running assembly.

Assuming you're using Visual Studio as your IDE, you can right click the desired project → Add → New item → Application Configuration File

This will add App.config to the project folder, put your settings in there under <appSettings> section. In case you're not using Visual Studio and adding the file manually, make sure to give it such name: DllName.dll.config, otherwise the below code won't work properly.

Now to read from this file have such function:

string GetAppSetting(Configuration config, string key)
{
    KeyValueConfigurationElement element = config.AppSettings.Settings[key];
    if (element != null)
    {
        string value = element.Value;
        if (!string.IsNullOrEmpty(value))
            return value;
    }
    return string.Empty;
}

And to use it:

Configuration config = null;
string exeConfigPath = this.GetType().Assembly.Location;
try
{
    config = ConfigurationManager.OpenExeConfiguration(exeConfigPath);
}
catch (Exception ex)
{
    //handle errror here.. means DLL has no sattelite configuration file.
}

if (config != null)
{
    string myValue = GetAppSetting(config, "myKey");
    ...
}

You'll also have to add reference to System.Configuration namespace in order to have the ConfigurationManager class available.

When building the project, in addition to the DLL you'll have DllName.dll.config file as well, that's the file you have to publish with the DLL itself.

The above is basic sample code, for those interested in a full scale example, please refer to this other answer.

EQUIVALENT, The adjective equivalent is used when something has the same value, amount, meaning etc. as another thing. The most common preposition  The adjective equivalent is used when something has the same value, amount, meaning etc. as another thing. The most common preposition used with this adjective is to : 150 grams are equivalent to a medium-sized potato.

Unfortunately, you can only have one app.config file per executable, so if you have DLL’s linked into your application, they cannot have their own app.config files.

Solution is: You don't need to put the App.config file in the Class Library's project. You put the App.config file in the application that is referencing your class library's dll.

For example, let's say we have a class library named MyClasses.dll which uses the app.config file like so:

string connect = 
ConfigurationSettings.AppSettings["MyClasses.ConnectionString"];

Now, let's say we have an Windows Application named MyApp.exe which references MyClasses.dll. It would contain an App.config with an entry such as:

<appSettings>
    <add key="MyClasses.ConnectionString"
         value="Connection string body goes here" />
</appSettings>

OR

An xml file is best equivalent for app.config. Use xml serialize/deserialize as needed. You can call it what every you want. If your config is "static" and does not need to change, your could also add it to the project as an embedded resource.

Hope it gives some Idea

Equivalent TO or OF, I learned a simple trick a long, long time ago that still serves me to this day when dealing with prepositions, which admittedly, as a native  Science definitions for equivalent Of or relating to a relation between two elements that is reflexive, symmetric, and transitive. Having a one-to-one correspondence, as between parts. Two triangles having the same area are equivalent, as are two congruent geometric figures.

Configuration files are application-scoped and not assembly-scoped. So you'll need to put your library's configuration sections in every application's configuration file that is using your library.

That said, it is not a good practice to get configuration from the application's configuration file, specially the appSettings section, in a class library. If your library needs parameters, they should probably be passed as method arguments in constructors, factory methods, etc. by whoever is calling your library. This prevents calling applications from accidentally reusing configuration entries that were expected by the class library.

That said, XML configuration files are extremely handy, so the best compromise that I've found is using custom configuration sections. You get to put your library's configuration in an XML file that is automatically read and parsed by the framework and you avoid potential accidents.

You can learn more about custom configuration sections on MSDN and also Phil Haack has a nice article on them.

vs. "[a/the] equivalent for" vs., Learn how to use Equivalent using many example sentences. Learn collocations of Equivalent with free vocabulary lessons. Here, 'equivalent' is an adjective. The dog's age is equivalent of 150 in human age. is this correct?? No. The dog's age is the equivalent of 150 in human years.Here, you are using 'equivalent' as a noun, so you need an article.

public class ConfigMan
{
    #region Members

    string _assemblyLocation;
    Configuration _configuration;

    #endregion Members

    #region Constructors

    /// <summary>
    /// Loads config file settings for libraries that use assembly.dll.config files
    /// </summary>
    /// <param name="assemblyLocation">The full path or UNC location of the loaded file that contains the manifest.</param>
    public ConfigMan(string assemblyLocation)
    {
        _assemblyLocation = assemblyLocation;
    }

    #endregion Constructors

    #region Properties

    Configuration Configuration
    {
        get
        {
            if (_configuration == null)
            {
                try
                {
                    _configuration = ConfigurationManager.OpenExeConfiguration(_assemblyLocation);
                }
                catch (Exception exception)
                {
                }
            }
            return _configuration;
        }
    }

    #endregion Properties

    #region Methods

    public string GetAppSetting(string key)
    {
        string result = string.Empty;
        if (Configuration != null)
        {
            KeyValueConfigurationElement keyValueConfigurationElement = Configuration.AppSettings.Settings[key];
            if (keyValueConfigurationElement != null)
            {
                string value = keyValueConfigurationElement.Value;
                if (!string.IsNullOrEmpty(value)) result = value;
            }
        }
        return result;
    }

    #endregion Methods
}

Just for something to do, I refactored the top answer into a class. The usage is something like:

ConfigMan configMan = new ConfigMan(this.GetType().Assembly.Location);
var setting = configMan.GetAppSetting("AppSettingsKey");

How to Use Equivalent with Example Sentences, something that is equivalent. QUIZZES. PUT YOUR 5TH GRADE VOCABULARY KNOWLEDGE TO THE TEST. Try this round of our teacher-selected  When there's money due Lockwood, he wants it, and most times he gets it or its equivalent. The very odour of those plums in Johnny's nostrils was the equivalent of ecstasy. This quiet lie was equivalent to a confession of everything. The presentation of the adarga was equivalent to an offer of peace.

If you add Settings to a Class Library project in Visual Studio (Project Properties, Settings), it will add an app.config file to your project with the relevant userSettings/applicatioNSettings sections, and the default values for these settings from your Settings.settings file.

However this configuration file will not be used at runtime - instead the class library uses the configuration file of its hosting application.

I believe the main reason for generating this file is so that you can copy/paste the settings into the host application's configuration file.

Equivalent, One dollar is equivalent to/of one Australia dollar. Are both "to" and "of" correct in this case? But if we use the word "equivalent" as a noun and add the word "the", we can use "of". One dollar is equivalent to one Australian dollar. One dollar is the equivalent of one Australian dollar. Click to expand Here is my understanding about the usage of "equivalent to" and "equivalent of".

equivalent to vs equivalent of, How to use equivalent in a sentence. Example sentences with the word equivalent. equivalent example sentences. Definition of equivalent. 1 : equal in force, amount, or value also : equal in area or volume but not superposable a square equivalent to a triangle. 2a : like in signification or import. b : having logical equivalence equivalent statements. 3 : corresponding or virtually identical especially in effect or function.

Use equivalent in a sentence, From Longman Dictionary of Contemporary Englishequivalente‧quiv‧a‧lent1 /​ɪˈkwɪvələnt/ ○○○ W3 AWL adjective SAMEEQUALhaving the same value,  Fractions Solve for Unknown X Calculator to find an equivalent fraction. Paste this link in email, text or social media. Find equivalent fractions. Enter a fraction, mixed number or integer to get fractions that are equivalent to your input. Equivalent fractions are fractions with different numbers representing the same part of a whole.

equivalent, Synonyms for be equivalent to at Thesaurus.com with free online thesaurus, antonyms, and definitions. Find descriptive alternatives for be equivalent to. This list is organized by symbol type and is intended to facilitate finding an unfamiliar symbol by its visual appearance. For a related list organized by mathematical topic, see List of mathematical symbols by subject. That list also includes LaTeX and HTML markup, and Unicode code points for each symbol (note that this article doesn't have

Comments
  • @Rodney try changing string exeConfigPath = this.GetType().Assembly.Location; to something like: string exeConfigPath = @"C:\MyFolder\DllFolder\ExeName.exe";
  • Any idea how to do this if the dll is being copied to some unknown folder by the resharper unit testing tool?
  • A tip for anyone else implementing this: to automate the generation of DllName.dll.config by referencing applications, I simply renamed app.config to DllName.dll.config, and changed the "Copy to Output Directory" property to "Copy always". Also, my need was for connection strings, which can be retrieved using config.ConnectionStrings.ConnectionStrings[connStringName].ConnectionString.
  • the app.cfg file name is very important to read the appcfg values, the file name should be "DLL_NAME.DLL.CONFIG"
  • Correction to my last comment. In my VS2017 solution, by removing my new, non-working App.config files from my test & DLL projects and just re-adding it to my test project it suddenly starting working! My App.config setting now automatically get included in the DLL.configs. What a relief!
  • ConfigurationSettings is now obsolete and replaced by ConfigurationManager, so the equivalent would now be ConfigurationManager.AppSettings
  • down vote. the question is per dll and not per app. best solution: stackoverflow.com/a/5191101/2935383
  • I suspect this suggestion won't work in the case of late-bound dlls which would have no knowledge of the executable calling them.
  • " it is not a good practice to get configuration from a configuration file in a class library" - I strongly disagree with this. For example, a DAL class library should normally get configuration data such as connection strings from the application configuration file rather than having this information passed from the BLL tier. Any Framework classes that use configuration (e.g. ASP.NET Membership) work in this way.
  • I modified my answer slightly. I still stand by what I said, but you're right, I never intended to imply that configuration files should not be used at all. What I meant was that, instead of convention-based appSettings, custom sections offer a great alternative; it is pretty much what ASP.NET Membership uses after all.
  • This should be the accepted answer. Very compact and "works right out of the box". Good stuff
  • Brilliant! This helped me to get my Windows Application Driver automated tests running on target machines. The dlls in my case were from a test project. The only thing I would add is that in Win App Driver (and possibly other forms of automated testing), the BaseDirectory is actually the output folder which changes each time. I had to substring like this...AppDomain.CurrentDomain.BaseDirectory.Substring(0, AppDomain.CurrentDomain.BaseDirectory.IndexOf("TestResults")). this way I could cut out the unwanted output folder as my config file was in the same folder as my test dlls.
  • Caveat to the above: when running xUnit tests on your .NET assembly DLL, xUnit will read the library's .config, at runtime. And it will ignore any App.config added to the test or DLL project.
  • Please, review the vote for deletion. My mistake was send the answer while writing it.