title: Getting Internal server Error when i run my Azure Function in the Portal
body: <p>I have created and published a Http triggered Azure function from visual studio.The function is for connecting to the iot hub and getting the module twin properties.</p>
  
  <p>I have configured the <strong>local.settings.json</strong> file with the module connection string and also added the same in the application settings in the portal.
  But when I run the function in the portal its giving me <strong>internal server error 500.</strong></p>
  
  <p>Azure function version I am running is v1.</p>
  
  <p>json files i am using:</p>
  
  <p><strong>local.settings.json</strong></p>
  
  <pre><code>{
        "IsEncrypted": false,
        "Values": {
          "AzureWebJobsStorage": "xxxxxxxx",
          "AzureWebJobsDashboard": "xxxxxx",
          "FUNCTIONS_WORKER_RUNTIME": "dotnet",
          "ModuleConnectionString": "xxxxxxxxx"
        }
      }
  </code></pre>
  
  <p><strong>host.json</strong></p>
  
  <pre><code>{
    "http": {
  
  "routePrefix": "api",
  
  "maxOutstandingRequests": 20,
  
  "maxConcurrentRequests": 10,
  
  "dynamicThrottlesEnabled": false
  
      },
  
   "version": "2.0"
  
  }
  </code></pre>
  
  <p><strong>function.json</strong></p>
  
  <pre><code>{
    "generatedBy": "Microsoft.NET.Sdk.Functions-1.0.19",
    "configurationSource": "attributes",
    "bindings": [
      {
        "type": "httpTrigger",
        "methods": [
          "get",
          "post"
        ],
        "authLevel": "function",
        "name": "req"
      }
    ],
    "disabled": false,
    "scriptFile": xxxx.dll",
    "entryPoint": "xxxxxxxx.Run"
  }
  </code></pre>
  
  <p>following is the code:</p>
  
  <p><strong>function1.cs</strong></p>
  
  <pre><code>    public static class Function1
      {
          [FunctionName("Function1")]
          public static async Task Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]HttpRequest req, ILogger log)
          {
              log.LogInformation("C# HTTP trigger function processed a request.");
  
  
              var moduleConnectionString = Environment.GetEnvironmentVariable("ModuleConnectionString", EnvironmentVariableTarget.Process);
  
  
              ModuleClient _moduleClient = ModuleClient.CreateFromConnectionString(moduleConnectionString, TransportType.Amqp);
  
              var sample = new TwinSample(_moduleClient);
              await sample.RunSampleAsync();
         }
      }
  </code></pre>
  
  <p><strong>twin.cs</strong></p>
  
  <pre><code>class TwinSample
      {
  
          private ModuleClient _moduleClient;
  
  
          public TwinSample(ModuleClient moduleClient)
          {
              this._moduleClient = _moduleClient;
          }
  
  
          public async Task&lt;string&gt; RunSampleAsync()
          {
              Console.WriteLine("Retrieving twin...");
              Twin twin = await _moduleClient.GetTwinAsync().ConfigureAwait(false);
  
              Console.WriteLine("\tInitial twin value received:");
  
              Console.WriteLine($"\t{twin.ToJson()}");
              return twin.ToJson();
          }
      }
  </code></pre>
  
  <p>I have tried changing the runtime version from 1 to 2 and vice versa. Still its not working. Also under Application Setting I have set </p>
  
  <p>WEBSITE_NODE_DEFAULT_VERSION</p>
  
  <p>to 8.11.1.from 6.5.0.</p>
  
  <p>Can any one help please me resolve this issue?</p>