title: Why does Azure CloudConfigurationManager.GetSetting return null
body: <p>I have a cloud service web role project that runs locally in the emulator, but does not run when deployed.  The error given is as follows:</p>
  
  <pre><code>[ArgumentNullException: Value cannot be null.
  Parameter name: connectionString]
     Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse(String connectionString) in e:\projects\azure-sdk-for-net\microsoft-azure-api\Services\Storage\Lib\Common\CloudStorageAccount.cs:344
     Candor.WindowsAzure.Storage.Table.CloudTableProxy`1.GetTable() in c:\Users\micha_000\Documents\GitHub\candor-common\Candor.WindowsAzure\Storage\Table\CloudTableProxy.cs:66
     Candor.WindowsAzure.Storage.Table.CloudTableProxy`1.Get(String partitionKey, String rowKey) in c:\Users\micha_000\Documents\GitHub\candor-common\Candor.WindowsAzure\Storage\Table\CloudTableProxy.cs:117
     Candor.WindowsAzure.Logging.Common.Table.CloudTableLogger.get_Configuration() +218
     Candor.WindowsAzure.Logging.Common.Table.CloudTableLogger.get_IsInfoEnabled() +9
     Common.Logging.Factory.AbstractLogger.Info(Object message) in c:\_oss\common-logging\src\Common.Logging.Core\Logging\Factory\AbstractLogger.cs:503
     Candor.Configuration.Provider.ProviderCollection`1.SetActiveProvider(T provider) in c:\Users\micha_000\Documents\GitHub\candor-common\Candor\Configuration\Provider\ProviderCollection.cs:169
     Candor.Configuration.Provider.ProviderResolver`1.AppendActive(T provider) in c:\Users\micha_000\Documents\GitHub\candor-common\Candor\Configuration\Provider\ProviderResolver.cs:77
     SHM.PublicMvcWeb.App_Start.ProviderBootstrapper.InitProviders() in c:\Users\micha_000\Documents\Git-Repos\shm-main\SHM.PublicMvcWeb\App_Start\ProviderBootstrapper.cs:23
     SHM.PublicMvcWeb.App_Start.ProviderBootstrapper.PostStartup() in c:\Users\micha_000\Documents\Git-Repos\shm-main\SHM.PublicMvcWeb\App_Start\ProviderBootstrapper.cs:18
  </code></pre>
  
  <p>You can see the code for the relevant lines shown in the stack trace on github.</p>
  
  <p><a href="https://github.com/michael-lang/candor-common/" rel="nofollow">https://github.com/michael-lang/candor-common/</a></p>
  
  <p>The lines leading to the error in CloudTableProxy are:</p>
  
  <pre><code>            if (String.IsNullOrWhiteSpace(_connectionName))
                  throw new InvalidOperationException("The Cloud ConnectionName has not been configured.");
              if (_account == null)
                  _account = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting(_connectionName));
  </code></pre>
  
  <p>Since it does not throw the custom error "The cloud connectionName has not been configured.", that tells me that _connectionName passed into CloudConfigurationManager.GetSetting is not null.  So CloudConfigurationManager is the call returning null for the supplied name.  Given that this name does return a value when running locally, I am not sure why it isn't found when deployed to my cloud web role.  If the connection name was entered as a typo, then it wouldn't work locally either.  To be sure, here is my common logging configuration naming the connection to be used:</p>
  
  <pre><code>  &lt;common&gt;
      &lt;logging&gt;
        &lt;factoryAdapter type="Candor.WindowsAzure.Logging.Common.Table.CloudTableLoggerFactoryAdapter, Candor.WindowsAzure.Logging.Common"&gt;
          &lt;arg key="connectionName" value="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" /&gt;
        &lt;/factoryAdapter&gt;
      &lt;/logging&gt;
    &lt;/common&gt;
  </code></pre>
  
  <p>I also have an entirely different solution with a cloud service web role using the same Candor.Common components, so I don't believe they are the problem.</p>
  
  <p>I am using the same laptop to develop both solutions, and so both are using the Azure 2.2 Tools version.  Inspecting the properties of the Cloud Service project in each solution verifies this.</p>
  
  <p>I inspected every component and NuGet package reference to be sure there are no version mismatches through the solution.  The same components are set to copy-local=true between the working solution and this non-working solution.  They also have the same binding redirects.  Although this was my biggest issue, now resolved, before running into this connection issue.</p>
  
  <p>The non-working service deployment configuration:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;ServiceConfiguration serviceName="SHM.AzureService.PublicMvcWeb" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" osFamily="4" osVersion="*" schemaVersion="2013-10.2.2"&gt;
    &lt;Role name="SHM.PublicMvcWeb"&gt;
      &lt;Instances count="1" /&gt;
      &lt;ConfigurationSettings&gt;
        &lt;Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="DefaultEndpointsProtocol=https;AccountName=(redacted);AccountKey=(redacted)" /&gt;
        &lt;Setting name="DefaultTableConnection" value="DefaultEndpointsProtocol=https;AccountName=(redacted);AccountKey=(redacted)" /&gt;
        &lt;Setting name="UserTableConnection" value="DefaultEndpointsProtocol=https;AccountName=(redacted);AccountKey=(redacted)" /&gt;
        &lt;Setting name="UserSaltTableConnection" value="DefaultEndpointsProtocol=https;AccountName=(redacted);AccountKey=(redacted)" /&gt;
        &lt;Setting name="UserAuditTableConnection" value="DefaultEndpointsProtocol=https;AccountName=(redacted);AccountKey=(redacted)" /&gt;
      &lt;/ConfigurationSettings&gt;
    &lt;/Role&gt;
  &lt;/ServiceConfiguration&gt;
  </code></pre>
  
  <p>I also recently tried putting these same connection names in the web application's appsettings.  This was in response to a comment 3 years ago that their code was executing before RoleEnvironment.OnStart.  But this attempt still results in the same error.</p>
  
  <p>Here is what the attempt looked like:</p>
  
  <pre><code>  &lt;appSettings&gt;
      &lt;add key="webpages:Version" value="3.0.0.0" /&gt;
      &lt;add key="webpages:Enabled" value="false" /&gt;
      &lt;add key="ClientValidationEnabled" value="true" /&gt;
      &lt;add key="UnobtrusiveJavaScriptEnabled" value="true" /&gt;
      &lt;add key="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="DefaultEndpointsProtocol=https;AccountName=(redacted);AccountKey=(redacted)"/&gt;
      &lt;add key="DefaultTableConnection" value="DefaultEndpointsProtocol=https;AccountName=(redacted);AccountKey=(redacted)"/&gt;
      &lt;add key="UserTableConnection" value="DefaultEndpointsProtocol=https;AccountName=(redacted);AccountKey=(redacted)"/&gt;
      &lt;add key="UserSaltTableConnection" value="DefaultEndpointsProtocol=https;AccountName=(redacted);AccountKey=(redacted)"/&gt;
      &lt;add key="UserAuditTableConnection" value="DefaultEndpointsProtocol=https;AccountName=(redacted);AccountKey=(redacted)"/&gt;
    &lt;/appSettings&gt;
  </code></pre>
  
  <p>This code in error does run on start of the application using WebActivator 2.0.6, wheras my working solution uses WebActivator 2.0.4.  But the release notes of WebActivator only shows compilation change from Debug to "Retail" and a license change between the two versions, and those changes were a year ago.</p>
  
  <p>In case timing was the issue, I also tried adding a Thread.Sleep(1000) just before the call in error, and it didn't work either, so I am going to remove it.</p>
  
  <pre><code>using System.Threading;
  using Candor.Configuration.Provider;
  using Candor.Security;
  using Candor.Security.Cryptography;
  using Candor.Security.Web;
  
  [assembly: WebActivatorEx.PreApplicationStartMethod(typeof(StopHarassingMe.PublicMvcWeb.App_Start.ProviderBootstrapper), "PreStartup")]
  [assembly: WebActivatorEx.PostApplicationStartMethod(typeof(StopHarassingMe.PublicMvcWeb.App_Start.ProviderBootstrapper), "PostStartup")]
  
  namespace SHM.PublicMvcWeb.App_Start
  {
      public class ProviderBootstrapper
      {
          public static void PreStartup()
          {
          }
          public static void PostStartup()
          {
              Thread.Sleep(1000); //let RoleEnvironment finish startup first or connectionstrings are not available.
              InitProviders();
          }
  
          private static void InitProviders()
          {
              ProviderResolver&lt;HashProvider&gt;.Configure()
                  .AppendActive(new SHA2HashProvider("sha2") { IsObsolete = false, SaltModifier = "" });
          }
      }
  }
  </code></pre>
  
  <p>This is the first provider configured in both the working and non-working solutions.</p>
  
  <p>Here is a list of the packages used by the web application in error:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;packages&gt;
    &lt;package id="Antlr" version="3.5.0.2" targetFramework="net45" /&gt;
    &lt;package id="Candor.Core" version="1.4.1.0" targetFramework="net45" /&gt;
    &lt;package id="Candor.jQuery.AutoAsync" version="4.0.0.50129" targetFramework="net45" /&gt;
    &lt;package id="Candor.Security" version="2.4.0.0" targetFramework="net451" /&gt;
    &lt;package id="Candor.Security.AzureStorageProvider" version="2.3.2.0" targetFramework="net451" /&gt;
    &lt;package id="Candor.Web.Mvc" version="1.0.3.0" targetFramework="net451" /&gt;
    &lt;package id="Candor.Web.Mvc.ErrorHandler" version="1.0.0.0" targetFramework="net45" /&gt;
    &lt;package id="Candor.Web.Mvc.Security" version="2.1.0.0" targetFramework="net45" /&gt;
    &lt;package id="Candor.WindowsAzure" version="1.3.0.0" targetFramework="net451" /&gt;
    &lt;package id="Candor.WindowsAzure.Logging.Common" version="1.1.1.0" targetFramework="net451" /&gt;
    &lt;package id="Common.Logging" version="2.2.0" targetFramework="net45" /&gt;
    &lt;package id="Common.Logging.Core" version="2.2.0" targetFramework="net45" /&gt;
    &lt;package id="form2js" version="1.0.0.30224" targetFramework="net45" /&gt;
    &lt;package id="jQuery" version="2.1.4" targetFramework="net451" /&gt;
    &lt;package id="jQuery.UI.Combined" version="1.8.20.1" targetFramework="net45" /&gt;
    &lt;package id="jQuery.Validation" version="1.13.1" targetFramework="net45" /&gt;
    &lt;package id="MarkdownSharp" version="1.13.0.0" targetFramework="net451" /&gt;
    &lt;package id="Microsoft.AspNet.Mvc" version="5.2.3" targetFramework="net45" /&gt;
    &lt;package id="Microsoft.AspNet.Razor" version="3.2.3" targetFramework="net45" /&gt;
    &lt;package id="Microsoft.AspNet.Web.Optimization" version="1.1.3" targetFramework="net45" /&gt;
    &lt;package id="Microsoft.AspNet.WebApi" version="5.2.3" targetFramework="net45" /&gt;
    &lt;package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net45" /&gt;
    &lt;package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net45" /&gt;
    &lt;package id="Microsoft.AspNet.WebApi.HelpPage" version="5.2.3" targetFramework="net451" /&gt;
    &lt;package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.3" targetFramework="net45" /&gt;
    &lt;package id="Microsoft.AspNet.WebPages" version="3.2.3" targetFramework="net45" /&gt;
    &lt;package id="Microsoft.Data.Edm" version="5.6.0" targetFramework="net451" /&gt;
    &lt;package id="Microsoft.Data.OData" version="5.6.0" targetFramework="net451" /&gt;
    &lt;package id="Microsoft.jQuery.Unobtrusive.Validation" version="3.2.3" targetFramework="net45" /&gt;
    &lt;package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" /&gt;
    &lt;package id="Microsoft.WindowsAzure.ConfigurationManager" version="2.0.1.0" targetFramework="net45" /&gt;
    &lt;package id="Modernizr" version="2.8.3" targetFramework="net45" /&gt;
    &lt;package id="Newtonsoft.Json" version="6.0.8" targetFramework="net45" /&gt;
    &lt;package id="Respond" version="1.4.2" targetFramework="net45" /&gt;
    &lt;package id="RestSharp" version="105.0.1" targetFramework="net451" /&gt;
    &lt;package id="System.Spatial" version="5.6.0" targetFramework="net451" /&gt;
    &lt;package id="T4MVC" version="3.7.4" targetFramework="net45" /&gt;
    &lt;package id="T4MVCExtensions" version="3.7.4" targetFramework="net45" /&gt;
    &lt;package id="Twilio" version="4.0.3" targetFramework="net451" /&gt;
    &lt;package id="Twilio.Mvc" version="3.1.15" targetFramework="net451" /&gt;
    &lt;package id="Twilio.TwiML" version="3.3.6" targetFramework="net451" /&gt;
    &lt;package id="WebActivatorEx" version="2.0.6" targetFramework="net451" /&gt;
    &lt;package id="WebGrease" version="1.6.0" targetFramework="net45" /&gt;
    &lt;package id="WindowsAzure.Storage" version="2.1.0.3" targetFramework="net45" /&gt;
  &lt;/packages&gt;
  </code></pre>
  
  <p>There are a couple package differences between my working and non-working solution, but I didn't think these were applicable to the error.  I went from MVC 5.0 to 5.2.3, upgraded javascript related packages, and Candor.WindowsAzure from 1.2.10 to 1.3.  That may seem relevant, but the only code change was to replace the implementation of a batch update method.</p>
  
  <p>WORKING SOLUTION PROJECT PACKAGES:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;packages&gt;
    &lt;package id="Antlr" version="3.5.0.2" targetFramework="net45" /&gt;
    &lt;package id="Candor.Core" version="1.4.1.0" targetFramework="net451" /&gt;
    &lt;package id="Candor.jQuery.AutoAsync" version="3.5.0.40210" targetFramework="net451" /&gt;
    &lt;package id="Candor.Security" version="2.4.0.0" targetFramework="net451" /&gt;
    &lt;package id="Candor.Security.AzureStorageProvider" version="2.3.2.0" targetFramework="net451" /&gt;
    &lt;package id="Candor.Web.Mvc" version="1.0.3.0" targetFramework="net451" /&gt;
    &lt;package id="Candor.Web.Mvc.ErrorHandler" version="1.0.0.0" targetFramework="net45" /&gt;
    &lt;package id="Candor.Web.Mvc.Security" version="2.1.0.0" targetFramework="net45" /&gt;
    &lt;package id="Candor.WindowsAzure" version="1.2.10.0" targetFramework="net451" /&gt;
    &lt;package id="Candor.WindowsAzure.Logging.Common" version="1.1.1.0" targetFramework="net451" /&gt;
    &lt;package id="Common.Logging" version="2.2.0" targetFramework="net451" /&gt;
    &lt;package id="Common.Logging.Core" version="2.2.0" targetFramework="net451" /&gt;
    &lt;package id="form2js" version="1.0.0.30224" targetFramework="net45" /&gt;
    &lt;package id="jQuery" version="2.0.3" targetFramework="net45" /&gt;
    &lt;package id="jQuery.UI.Combined" version="1.10.3" targetFramework="net45" /&gt;
    &lt;package id="jQuery.Validation" version="1.11.1" targetFramework="net45" /&gt;
    &lt;package id="MarkdownSharp" version="1.13.0.0" targetFramework="net451" /&gt;
    &lt;package id="Microsoft.AspNet.Mvc" version="5.0.0" targetFramework="net45" /&gt;
    &lt;package id="Microsoft.AspNet.Razor" version="3.0.0" targetFramework="net45" /&gt;
    &lt;package id="Microsoft.AspNet.Web.Optimization" version="1.1.2" targetFramework="net45" /&gt;
    &lt;package id="Microsoft.AspNet.WebApi" version="5.0.0" targetFramework="net45" /&gt;
    &lt;package id="Microsoft.AspNet.WebApi.Client" version="5.0.0" targetFramework="net45" /&gt;
    &lt;package id="Microsoft.AspNet.WebApi.Core" version="5.0.0" targetFramework="net45" /&gt;
    &lt;package id="Microsoft.AspNet.WebApi.HelpPage" version="5.0.0" targetFramework="net45" /&gt;
    &lt;package id="Microsoft.AspNet.WebApi.OData" version="5.0.0" targetFramework="net45" /&gt;
    &lt;package id="Microsoft.AspNet.WebApi.WebHost" version="5.0.0" targetFramework="net45" /&gt;
    &lt;package id="Microsoft.AspNet.WebPages" version="3.0.0" targetFramework="net45" /&gt;
    &lt;package id="Microsoft.AspNet.WebPages.Data" version="3.0.0" targetFramework="net45" /&gt;
    &lt;package id="Microsoft.AspNet.WebPages.WebData" version="3.0.0" targetFramework="net45" /&gt;
    &lt;package id="Microsoft.Data.Edm" version="5.6.0" targetFramework="net45" /&gt;
    &lt;package id="Microsoft.Data.OData" version="5.6.0" targetFramework="net45" /&gt;
    &lt;package id="Microsoft.jQuery.Unobtrusive.Ajax" version="3.0.0" targetFramework="net45" /&gt;
    &lt;package id="Microsoft.jQuery.Unobtrusive.Validation" version="3.0.0" targetFramework="net45" /&gt;
    &lt;package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" /&gt;
    &lt;package id="Microsoft.WindowsAzure.ConfigurationManager" version="2.0.1.0" targetFramework="net45" /&gt;
    &lt;package id="Modernizr" version="2.7.1" targetFramework="net45" /&gt;
    &lt;package id="Newtonsoft.Json" version="5.0.8" targetFramework="net45" /&gt;
    &lt;package id="SlidesJS" version="3.0.4" targetFramework="net451" /&gt;
    &lt;package id="System.Spatial" version="5.6.0" targetFramework="net45" /&gt;
    &lt;package id="T4MVC" version="3.7.4" targetFramework="net45" /&gt;
    &lt;package id="T4MVCExtensions" version="3.7.4" targetFramework="net45" /&gt;
    &lt;package id="WebActivatorEx" version="2.0.4" targetFramework="net45" /&gt;
    &lt;package id="WebGrease" version="1.6.0" targetFramework="net451" /&gt;
    &lt;package id="WindowsAzure.Storage" version="2.1.0.3" targetFramework="net45" /&gt;
  &lt;/packages&gt;
  </code></pre>