title: Microsoft Exchange Transport Agent
body: <p>I am building a transport agent for Microsoft Exchange server. The logic I have implemented so far works. Now, I want to store some of the variables in DB. I have opted for a repository pattern and when I try to extract a connection string from App.Config file I am receiving a NullReference Exception:</p>
  
  <pre><code>public class ConfigRepository : IConfigRepository, IDisposable
  {
      private string configString = System.Configuration.ConfigurationManager.ConnectionStrings["citadelEAPEntities"].ConnectionString;
      // private string configString = "..."; here I tried to write the string directly .
      private string configValProc = "[dbo].[GetConfigValue]";
      private SqlConnection connection;
  
      public ConfigRepository()
      {
          connection = new SqlConnection(configString);
      }
  
      // other logic and implementation of interfaces
  }
  </code></pre>
  
  <p>The same class is implemented in a test console app, which works fine (with the same connection string stored in the same manner in the app.config file). 
  I cannot understand the reason for this exception. The transporter agent class instantiates a ConfigRepository class within a 'using' statement and the moment it reaches the constructor function upon the initialization of the connection string variable via config manager an exception gets thrown. Obviously when I use the connection string in a hard coded manner everything works just fine.</p>
  
  <p>Is the transporter agent assembly somehow limited while referencing other assemblies (such as System.Configuration) ? Just weird. </p>