title: Azure Table Storage - CreateTableIfNotExists hanging - was previously working
body: <p>I have been struggling to get some code working on a new machine.. I thought I finally had it working but now when I run it the code hangs at the point of trying to create the table storage (or in actual fact get a reference to it, as it does already exist)... I know about having to make sure it's async all the way through and this code was working... I've now changed it to try and improve it and get it working on this machine, but something is not right... So in the constructor of the Repo I do this....</p>
  
  <pre><code>public LdsRepo() 
      {
  
          if (!GetTableRef("licensedatesummary").Result)
          {
              throw new Exception("It broke!");
          }
      }
  </code></pre>
  
  <p>and my GetTableReference Method (on the base class) is like this...</p>
  
  <pre><code>protected async Task&lt;bool&gt;  GetTableRef(string tableRef)
      {
          try
          {
              if (string.IsNullOrEmpty(StorageAccountName) || string.IsNullOrEmpty(AuthKey))
              {
                  throw new ArgumentNullException(nameof(tableRef),
                      "storageaccountname or authk are not set in the config");
              }
              if (_tableClient == null)
                  _tableClient =
                      new CloudStorageAccount(new StorageCredentials(StorageAccountName, AuthKey), true)
                          .CreateCloudTableClient();
              if (_table == null)
              {
                  // Create the CloudTable object that represents the referenced table.
                  _table = _tableClient.GetTableReference(tableRef);
                  var x =  _table.CreateIfNotExistsAsync();
                  return await x;
              }
              return true;
          }
          catch (Exception ex)
          {
              Trace.WriteLine(ex.Message);
              Trace.WriteLine(ex.ToString());
              return false;
          }
      }
  </code></pre>
  
  <p>and if it helps... this is my packages config...</p>
  
  <pre><code>&lt;packages&gt;
  &lt;package id="Microsoft.Azure.KeyVault.Core" version="1.0.0" targetFramework="net452" /&gt;
  &lt;package id="Microsoft.Data.Edm" version="5.7.0" targetFramework="net452" /&gt;
  &lt;package id="Microsoft.Data.OData" version="5.7.0" targetFramework="net452" /&gt;
  &lt;package id="Microsoft.Data.Services.Client" version="5.7.0" targetFramework="net452" /&gt;
  &lt;package id="Microsoft.Web.WebJobs.Publish" version="1.0.11" targetFramework="net452" /&gt;
  &lt;package id="Microsoft.WindowsAzure.ConfigurationManager" version="3.2.1" targetFramework="net452" /&gt;
  &lt;package id="Newtonsoft.Json" version="8.0.3" targetFramework="net452" /&gt;
  &lt;package id="System.Spatial" version="5.7.0" targetFramework="net452" /&gt;
  &lt;package id="WindowsAzure.Storage" version="7.0.0" targetFramework="net452" /&gt; &lt;/packages&gt;
  </code></pre>
  
  <p>And finally my actual WebApi controller....</p>
  
  <pre><code>[EnableCors(origins: "*", headers: "*", methods: "*")]
  [RoutePrefix("api")]
  public class LinkDataController : ApiController
  {
      private readonly IFloatingObjectRecordRepo _repo;
      public LinkDataController()
      {
          _repo = new FloatingObjectRecordRepo();
      }
      [HttpGet, Route("linkdata/{id}")]
      public async Task&lt;IHttpActionResult&gt; Get(string id)
      {
          try
          {
              if (string.IsNullOrEmpty(id))
              {
                  return BadRequest();
              }
              var retStr = await  _repo.SearchById(id);
              if (retStr == "Not found")
                  return new IsoncOkResult&lt;KeyValuePair&lt;string, string&gt;&gt;(
                      new KeyValuePair&lt;string, string&gt;(id, retStr), this);
              var g = Guid.NewGuid();
              var f = await _repo.Add(new FlorData
              {
                  CreatedBy = "Ais Integration Search",
                  Mmsi = id,
                  CreatedOn = DateTime.Now,
                  GeneratedId = g,
                  RowKey = g.ToString()
              });
              retStr = f.GeneratedId.ToString();
              return new IsoncOkResult&lt;KeyValuePair&lt;string, string&gt;&gt;(new KeyValuePair&lt;string, string&gt;(id, retStr), this);
          }
          catch (Exception ex)
          {
              Trace.TraceError($"Error Searching / Creating AIS Link Data: {ex}");
              return BadRequest(ex.ToString());
          }
      }
     }
  </code></pre>
  
  <p>I have searched on here quite extensively but every time it has been where someone hasn't followed the async chain all the way through, which I think I am doing?</p>