title: ConfigurationManager reading wrong file - Web.config instead of App.config
body: <p>I was working on ASP.NET MVC project and decided to extract some functionality to a separate class library project (in the same solution). </p>
  
  <p>I moved some of the elements in <code>&lt;appSettings&gt;&lt;/appSettings&gt;</code> from <code>Web.config</code> in main project (let's call it project A) to <code>App.config</code> in class library project (let's call it project B). I added a reference to System.Configuration.dll to access the ConfigurationManager in project B. </p>
  
  <p>Sample App.config file is for project B is below.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;configuration&gt;
    &lt;appSettings&gt;
      &lt;add key="Key1" value="Value1"/&gt;
      &lt;add key="Key2" value="Value2"/&gt;
    &lt;/appSettings&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>I access these settings as follows (in project B).</p>
  
  <pre><code>string key1 = ConfigurationManager.AppSettings["Key1"];
  string key2 = ConfigurationManager.AppSettings["Key2"];
  </code></pre>
  
  <p>I noticed that the values for <code>key1</code> and <code>key2</code> returned by <code>ConfigurationManager</code> are <code>null</code>. </p>
  
  <p>When debugging I see that <code>ConfigurationManager</code> pull values from the original <code>Web.config</code> in project A (the other entires in <code>&lt;appsettings&gt;&lt;/appsettings&gt;</code> section that I did not move to project B)!</p>
  
  <p>This does not make any sense to me. Could someone tell me what I am doing wrong, so I could access settings in App.config?</p>
  
  <p>Thanks.</p>