title: Azure Function with CosmosDb Binding Proper Local Setup
body: <p>I'm sure I'm missing something simple here, but I can't get this to work. I have installed the Azure Storage Simulator locally and have created an Azure Function 2.0 through Visual Studio 2019.</p>
  
  <p>I can run the function without a CosmosDb binding as follows:</p>
  
  <p><code>local.settings.json</code></p>
  
  <pre><code>{
    "IsEncrypted": false,
    "Values": {
      "AzureWebJobsStorage": "UseDevelopmentStorage=true",
      "FUNCTIONS_WORKER_RUNTIME": "dotnet",
      "EndpointUri": "https://localhost:8081",
      "PrimaryKey": "&lt;KEY_HERE&gt;"
    }
  }
  </code></pre>
  
  <p><code>Function.cs</code></p>
  
  <pre><code>public static class Function
  {
      [FunctionName("func")]
      public static async Task Run(
          [TimerTrigger("0 * * * * *")] TimerInfo myTimer,
          ILogger log
      )
      {
          log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
  
          var endpointUri = new Uri(Environment.GetEnvironmentVariable("EndpointUri", EnvironmentVariableTarget.Process));
          var primaryKey = Environment.GetEnvironmentVariable("PrimaryKey");
  
          using (var client = new DocumentClient(endpointUri, primaryKey))
          {
              var queryOptions = new FeedOptions { MaxItemCount = -1 };
              var documents = client.CreateDocumentQuery&lt;Doc&gt;(UriFactory.CreateDocumentCollectionUri("db_id", "col_id"), queryOptions);
  
              foreach (var document in documents)
              {
                ...
              }
          }
      }
  }
  </code></pre>
  
  <p>The code runs as expected and gets the documents that I have in my local storage emulator.</p>
  
  <p>I would like to switch this to utilize a CosmosDb binding though and can't seem to find the magical incantations needed to get it to work.</p>
  
  <p>I updated the method signature on <code>Function.cs</code> to:</p>
  
  <pre><code>public static async Task Run(
              [TimerTrigger("0 * * * * *")] TimerInfo myTimer,
              ILogger log,
              [CosmosDB(
                  databaseName: "db_id",
                  collectionName: "col_id",
                  ConnectionStringSetting = "AzureWebJobsStorage",
                  SqlQuery = "SELECT * FROM col_id")
              ] IEnumerable&lt;Doc&gt; documents
          )
  </code></pre>
  
  <p>When I run it though, I get the following error:</p>
  
  <blockquote>
    <p>[5/17/2019 3:09:29 PM] Executed 'func' (Failed,
    Id=8326b1c4-3dd5-461d-b8de-d777c5b925d8) [5/17/2019 3:09:29 PM]
    System.Private.CoreLib: Exception while executing function: func.
    Microsoft.Azure.WebJobs.Host: Exception binding parameter 'documents'.
    Microsoft.Azure.DocumentDB.Core: Value cannot be null. [5/17/2019
    3:09:29 PM] Parameter name: authKeyOrResourceToken.</p>
  </blockquote>
  
  <p>I've tried a number of other tinkerings all without any success.</p>
  
  <p>The first was to utilize the default full explicit connectionstring:
  <code>"AzureWebJobsStorage": "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;TableEndpoint=http://127.0.0.1:10002/devstoreaccount1;QueueEndpoint=http://127.0.0.1:10001/devstoreaccount1;",</code> as found in the <a href="https://docs.microsoft.com/en-us/azure/storage/common/storage-use-emulator#connect-to-the-emulator-account-using-the-well-known-account-name-and-key" rel="nofollow noreferrer">Azure docs</a>.</p>
  
  <p>Any idea how I can change the above to execute locally against my Azure Storage Emulator successfully?</p>