可以通过Azure函数绑定正确使用应用程序和本地设置吗?

时间:2019-01-03 00:08:24

标签: c# azure azure-functions

我正在Visual Studio 2017中开发一些使用EventHub,ServiceBus,SignalR,CosmosDB和其他绑定的Azure函数。许多绑定都有一个Connection或ConnectionStringSetting参数,应该将其设置为保存连接字符串的设置的名称。

例如:

[EventHubTrigger(eventHubName: "the-hub-name", Connection = "MySettingName")] TheRequestEventType request

我在local.settings.json的MySettingName部分中拥有Values值。所有这些都可以在本地运行和调试。

当我将MySettingName添加到Azure Functions应用程序上的“应用程序设置”并部署该应用程序时,这些东西将无法正常工作。应用启动时,我收到异常消息,指出连接字符串为空:Error indexing method 'MyEventHandler.Run' Value cannot be null. Parameter name: connectionString(下面提供了完整的调用堆栈)。

使用Connection或ConnectionStringSetting参数的正确方法是什么?

是否有一些必须使用的命名约定,例如APPSETTING_MySettingName

我一直在搜索有关此文件的文档,并且通常在“功能应用程序”中使用“应用程序设置”,但没有找到任何可解决此问题的方法,如果我错过了明显的内容,请先抱歉。

Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexingException:
   at Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexer+<IndexMethodAsync>d__17.MoveNext (Microsoft.Azure.WebJobs.Host, Version=3.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35Microsoft.Azure.WebJobs.Host, Version=3.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35: C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Indexers\FunctionIndexer.csMicrosoft.Azure.WebJobs.Host, Version=3.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35: 175)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexer+<IndexTypeAsync>d__13.MoveNext (Microsoft.Azure.WebJobs.Host, Version=3.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35Microsoft.Azure.WebJobs.Host, Version=3.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35: C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Indexers\FunctionIndexer.csMicrosoft.Azure.WebJobs.Host, Version=3.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35: 103)
Inner exception System.ArgumentNullException handled at Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexer+<IndexMethodAsync>d__17.MoveNext:
   at Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse (Microsoft.WindowsAzure.Storage, Version=9.3.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
   at Microsoft.Azure.EventHubs.Processor.EventProcessorHost..ctor (Microsoft.Azure.EventHubs.Processor, Version=2.1.0.0, Culture=neutral, PublicKeyToken=7e34167dcc6d6d8c)
   at Microsoft.Azure.WebJobs.EventHubs.EventHubOptions.GetEventProcessorHost (Microsoft.Azure.WebJobs.EventHubs, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35Microsoft.Azure.WebJobs.EventHubs, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35: C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Extensions.EventHubs\Config\EventHubOptions.csMicrosoft.Azure.WebJobs.EventHubs, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35: 247)
   at Microsoft.Azure.WebJobs.EventHubs.EventHubTriggerAttributeBindingProvider.TryCreateAsync (Microsoft.Azure.WebJobs.EventHubs, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35Microsoft.Azure.WebJobs.EventHubs, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35: C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Extensions.EventHubs\Triggers\EventHubTriggerAttributeBindingProvider.csMicrosoft.Azure.WebJobs.EventHubs, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35: 68)
   at Microsoft.Azure.WebJobs.Host.Triggers.CompositeTriggerBindingProvider+<TryCreateAsync>d__2.MoveNext (Microsoft.Azure.WebJobs.Host, Version=3.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35Microsoft.Azure.WebJobs.Host, Version=3.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35: C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Triggers\CompositeTriggerBindingProvider.csMicrosoft.Azure.WebJobs.Host, Version=3.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35: 22)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexer+<IndexMethodAsyncCore>d__18.MoveNext (Microsoft.Azure.WebJobs.Host, Version=3.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35Microsoft.Azure.WebJobs.Host, Version=3.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35: C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Indexers\FunctionIndexer.csMicrosoft.Azure.WebJobs.Host, Version=3.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35: 190)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexer+<IndexMethodAsync>d__17.MoveNext (Microsoft.Azure.WebJobs.Host, Version=3.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35Microsoft.Azure.WebJobs.Host, Version=3.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35: C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Indexers\FunctionIndexer.csMicrosoft.Azure.WebJobs.Host, Version=3.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35: 167)

2 个答案:

答案 0 :(得分:2)

您正确地将了这些连接字符串设置(例如MySettingName和相应的值)添加到Azure Functions的“应用程序设置”中。也没有命名约定。

“空值”异常可能是由于“应用程序设置”中缺少AzureWebJobsStorage而导致的,除Http触发器以外的所有触发器都需要此存储帐户连接字符串。存储帐户必须是支持blob,队列和表的通用帐户。

答案 1 :(得分:0)

它在本地调试时有效,这意味着您的local.settings.json是正确的,并且“ MySettingName”已正确配置。

据我了解,部署到Azure时不起作用。在Azure中运行时,它不会查看local.seetings.json。相反,Azure会查看功能应用程序的“应用程序设置”。

因此,编辑应用程序设置并在其中添加“ MySettingName”。那应该解决您的问题。

enter image description here