1

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 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Tom, I already have 'AzureWebJobsStorage' and 'AzureWebJobsDashboard' in my local setting.json file. Since you have mentioned other settings as well I have copied your file and updated 'AzureWebJobsStorage' and 'AzureWebJobsDashboard'. Result is same. It works fine if I move my code to Azure. Do I need to provide a value for LocalHttpPort, CORS, and SQLConnectionString ? I have not changed these. and I m not using SQL server so no string is there. I m running it from CLI cmd tool. Please help.
@user576510, There is no need to provide the cors and sql connectionstring if is not necessary and the default local http port is 7071. How to develop and test Azure Functions locally, please refer to this document. If any reproduced demo code, it will be more helpful.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.