title: Unable to read local.settings.json file when running Azure Function locally
body: <p>I am trying to read an environment variable while testing Azure Functions locally (using v1 .Net 4.7.1)</p>
  
  <p>Below is the function code:</p>
  
  <pre><code>[FunctionName( "test" )]
    public static async Task&lt;HttpResponseMessage&gt; Run( [HttpTrigger( AuthorizationLevel.Anonymous, "post", Route = null )]HttpRequestMessage req, TraceWriter log )
    {
  
       String s;
  
       log.Info( "test: Begin..." );
  
       s = System.Environment.GetEnvironmentVariable( "test" );
  
       if ( String.IsNullOrEmpty( s ) )
       {
          log.Info( "Unable to get environment key !!!!" );
       }
       else
       {
          log.Info( "Key value = " + s );
       }
  
    }
  </code></pre>
  
  <p>The local.settings.json file contains:</p>
  
  <pre><code>{
  "IsEncrypted": false,
  "Values": {
     "AzureWebJobsStorage": "UseDevelopmentStorage=true",
     "AzureWebJobsDashboard": "UseDevelopmentStorage=true",
     "test": "test_value"
     }
  }
  </code></pre>
  
  <p>The function compiles and runs, but the environment key value is never returned, the log always contains:</p>
  
  <pre><code> Unable to get environment key !!!!
  </code></pre>
  
  <p>The weird part is I have another project (same code as above) and it works just fine.  The only difference in the assemblies is the Microsoft.Net.Sdk.Functions DLL (1.0.19) vs (1.0.13) -- the current project (that does NOT work) is using 1.0.19 -- so I downgraded to 1.0.13 -- but it made NO DIFFERENCE !</p>
  
  <p><a href="https://i.stack.imgur.com/AokDn.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/AokDn.jpg" alt="project differences"></a></p>
  
  <p><strong>UPDATE: 9-Sep-2018</strong> - special thanks to Karishma Tiwari who steered me in the right direction:</p>
  
  <p>The problem was (as Karismha pointed out) that the local.settings.json file was NOT being copied to the output path, as shown below by comparing the settings in the project that is NOT working (on left), and the project that is working (right):</p>
  
  <p><a href="https://i.stack.imgur.com/N7AJg.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/N7AJg.jpg" alt="enter image description here"></a></p>
  
  <p>To solve:</p>
  
  <ol>
  <li>Right-click on local.settings.json -> Properties</li>
  <li>Change the "Copy to Output Directory" setting to: "Copy if newer"</li>
  </ol>
  
  <p>One other point to note is that <a href="https://docs.microsoft.com/en-us/azure/azure-functions/functions-dotnet-class-library#environment-variables" rel="noreferrer">MS documentation states</a> states:</p>
  
  <p>"... but we recommend that you use GetEnvironmentVariable ...",</p>
  
  <p>Problem solved.</p>