运行 VS 中的 Azure 函数和读取应用程序设置时出错

running Azure Function in VS and error on reading Application settings

我有一个功能,读取 "Application settings",这是男子气概的钥匙。它在 Azure 中运行良好,但是当我 运行 它通过错误从 VS 在本地运行时:

[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]

我也在本地添加了 App.config 相同的密钥,但这没有什么不同。请指导我如何修复它。我只想测试它在 Azure 中的工作情况。谢谢

编辑:

我已经按照 Tom Sun 的回复做了,但结果是一样的。复制了他的 json 文件,仅更改了 'AzureWebJobsStorage' 和 'AzureWebJobsDashboard',但在 运行ning 上得到了相同的效果。请帮忙。

如果您想在本地运行 Azure 功能,您可以在 local.settings.json 中配置"Applcation settings"。

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.

更新:

不需要提供cors和sqlconnectionstring如果不是 必须的,默认本地http端口是7071。如何在本地开发和测试Azure Functions,请参考这个document. How to develop with VS please refer to Azure Functions Tools for Visual Studio.