<p>I have an exe with an <code>App.Config</code> file. Now I want to create a wrapper dll around the exe in order to consume some of the functionalities.</p>

<p>The question is how can I access the app.config property in the exe from the wrapper dll?</p>

<p>Maybe I should be a little bit more in my questions, I have the following app.config content with the exe:</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
&lt;configuration&gt;
  &lt;appSettings&gt;
    &lt;add key="myKey" value="myValue"/&gt;
  &lt;/appSettings&gt;
&lt;/configuration&gt;
</code></pre>

<p>The question is how to how to get "myValue" out from the wrapper dll?</p>

<hr>

<p>thanks for your solution.</p>

<p>Actually my initial concept was to avoid XML file reading method or LINQ or whatever. My preferred solution was to use the <a href="http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.aspx" rel="noreferrer">configuration manager libraries and the like</a>.</p>

<p>I'll appreciate any help that uses the classes that are normally associated with accessing app.config properties. </p>

[{'answer_id': 53552, 'author': 'Gishu', 'author_id': 1695, 'author_profile': 'https://Stackoverflow.com/users/1695', 'pm_score': -1, 'selected': False, 'text': "<p>It's an xml file, you can use Linq-XML or DOM based approaches to parse out the relevant information.<br>\n(that said I'd question if there isn't a better design for whatever it is.. you're trying to achieve.)</p>\n"}, {'answer_id': 53553, 'author': 'Espo', 'author_id': 2257, 'author_profile': 'https://Stackoverflow.com/users/2257', 'pm_score': 5, 'selected': False, 'text': '<p>The <a href="http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.openmappedexeconfiguration(VS.80).aspx" rel="noreferrer">ConfigurationManager.OpenMappedExeConfiguration Method</a> will allow you to do this.</p>\n\n<p>Sample from the MSDN page:</p>\n\n<pre><code>static void GetMappedExeConfigurationSections()\n{\n    // Get the machine.config file.\n    ExeConfigurationFileMap fileMap =\n        new ExeConfigurationFileMap();\n    // You may want to map to your own exe.comfig file here.\n    fileMap.ExeConfigFilename = \n        @"C:\\test\\ConfigurationManager.exe.config";\n    System.Configuration.Configuration config =\n        ConfigurationManager.OpenMappedExeConfiguration(fileMap, \n        ConfigurationUserLevel.None);\n\n    // Loop to get the sections. Display basic information.\n    Console.WriteLine("Name, Allow Definition");\n    int i = 0;\n    foreach (ConfigurationSection section in config.Sections)\n    {\n        Console.WriteLine(\n            section.SectionInformation.Name + "\\t" +\n        section.SectionInformation.AllowExeDefinition);\n        i += 1;\n\n    }\n    Console.WriteLine("[Total number of sections: {0}]", i);\n\n    // Display machine.config path.\n    Console.WriteLine("[File path: {0}]", config.FilePath);\n}\n</code></pre>\n\n<hr>\n\n<p>EDIT: This should output the "myKey" value:</p>\n\n<pre><code>ExeConfigurationFileMap fileMap =\n    new ExeConfigurationFileMap();\nfileMap.ExeConfigFilename = \n    @"C:\\test\\ConfigurationManager.exe.config";\nSystem.Configuration.Configuration config =\n    ConfigurationManager.OpenMappedExeConfiguration(fileMap, \n    ConfigurationUserLevel.None);\nConsole.WriteLine(config.AppSettings.Settings["MyKey"].Value);\n</code></pre>\n'}, {'answer_id': 53557, 'author': 'alastairs', 'author_id': 5296, 'author_profile': 'https://Stackoverflow.com/users/5296', 'pm_score': 0, 'selected': False, 'text': '<p>I\'d second Gishu\'s point that there\'s another way.  Wouldn\'t it be better to abstact the common/"public" part of the EXE out into DLL create a wrapper EXE to run it?  This is certainly the more usual pattern of development.  Only the stuff that you wish to consume would go into the DLL, and the EXE would do all the stuff it currently does, minus what\'s gone into the DLL.  </p>\n'}, {'answer_id': 53642, 'author': 'lomaxx', 'author_id': 493, 'author_profile': 'https://Stackoverflow.com/users/493', 'pm_score': 2, 'selected': False, 'text': "<p>I think what you're looking for is:</p>\n\n<pre><code>System.Configuration.ConfigurationManager.OpenExeConfiguration(string path)\n</code></pre>\n"}, {'answer_id': 53776, 'author': 'Graviton', 'author_id': 3834, 'author_profile': 'https://Stackoverflow.com/users/3834', 'pm_score': 4, 'selected': True, 'text': '<p>After some testing, I found a way to do this.</p>\n\n<ol>\n<li>Add the App.Config file to the test project. Use "Add as a link" option.</li>\n<li>Use <code>System.Configuration.ConfigurationManager.AppSettings["myKey"]</code> to access the value.</li>\n</ol>\n'}, {'answer_id': 53784, 'author': 'tkrehbiel', 'author_id': 4925, 'author_profile': 'https://Stackoverflow.com/users/4925', 'pm_score': -1, 'selected': False, 'text': '<p>Adding a link in the IDE would only help during development.  I think lomaxx has the right idea: <code>System.Configuration.ConfigurationManager.OpenExeConfiguration.</code></p>\n'}]
['https://Stackoverflow.com/questions/53545', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3834/']