1
votes

I have a function which read "Application settings" which are manly keys. It works fine in Azure but when I run it locally from VS it through an error:

[27/02/2018 5:39:14 AM] A ScriptHost error has occurred
[27/02/2018 5:39:14 AM] Exception while executing function: GetFile. OOPInteg: Object reference not set to an instance of an object.
[27/02/2018 5:39:14 AM] Exception while executing function: GetFile
[27/02/2018 5:39:14 AM] Exception while executing function: GetFile. OOPInteg: Object reference not set to an instance of an object.
[27/02/2018 5:39:14 AM] Function completed (Failure, Id=463f7a76-b34c-42ba-aa84-ca1b496da288, Duration=61ms)
[27/02/2018 5:39:14 AM]

I have added App.config locally with same keys as well but it is not making a difference. Kindly guide how I can fix it. I just want to test it as it works in Azure. Thanks

EDIT:

I have done as per reply by Tom Sun but result is same. Have copied his json file changed only its 'AzureWebJobsStorage' and 'AzureWebJobsDashboard' but on running got same effect. Please help.

1

1 Answers

2
votes

If you want to run the Azure function locally, you could configurate the "Applcation settings" in the local.settings.json.

The file local.settings.json stores app settings, connection strings, and settings for Azure Functions Core Tools. It has the following structure:JSON

{
  "IsEncrypted": false,   
  "Values": {
    "AzureWebJobsStorage": "<connection string>", 
    "AzureWebJobsDashboard": "<connection string>" 
  },
  "Host": {
    "LocalHttpPort": 7071, 
    "CORS": "*" 
  },
  "ConnectionStrings": {
    "SQLConnectionString": "Value"
  }
}

These settings can also be read in your code as environment variables. In C#, use System.Environment.GetEnvironmentVariable or ConfigurationManager.AppSettings. In JavaScript, use process.env. Settings specified as a system environment variable take precedence over values in the local.settings.json file.

Update:

There is no need to provide the cors and sql connectionstring if it is not necessary and the default local http port is 7071. How to develop and test Azure Functions locally, please refer to this document. How to develop with VS please refer to Azure Functions Tools for Visual Studio.