0
votes

I am developing some Azure Functions in Visual Studio 2017 that use EventHub, ServiceBus, SignalR, CosmosDB and other bindings. Many of the bindings have a Connection or ConnectionStringSetting argument that is supposed to be set to the name of the setting that holds the connection string.

For example:

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

I have the MySettingName value in the Values section of my local.settings.json. This all works fine for running and debugging locally.

When I added MySettingName to the App Settings on the Azure Functions App and deployed the App things do not work. When the app starts I get exceptions stating that the connection string is null: Error indexing method 'MyEventHandler.Run' Value cannot be null. Parameter name: connectionString (full call stack provided below).

What is the correct way to use the Connection or ConnectionStringSetting arguments?

Is there some naming convention that must be used like APPSETTING_MySettingName?

I've been searching for documentation on this and using App Settings with Function Apps in general but not found anything that address this, sorry in advance if I've missed something obvious.

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

2 Answers

2
votes

You did it right that adding those Connection String settings(e.g. MySettingName and corresponding value)to the App Settings on the Azure Functions. There's no naming convention either.

The null value exception probably results from missing AzureWebJobsStorage in App Settings, this storage account connection string is required for all triggers except Http trigger. The storage account must be a general-purpose one that supports blobs, queues, and tables.

0
votes

The fact that it works when debugging locally means, your local.settings.json is correct and has "MySettingName" configured correctly.

As far as I can understand, it doesn't work when you deploy to Azure. When running in Azure, it doesn't look at local.seetings.json. Instead Azure looks at "Application Settings" of your function app.

So edit application settings and add "MySettingName" there. That should solve your issue.

enter image description here