Tany Tany - 1 year ago 106
C# Question

Azure function App settings is null after deployment

Here is my scenario:

  • I have a c# blob trigger azure function (alwaysON set to true).

  • I am setting the appsettings of the function app using
    New-AzureRmResource ps cmdlet.

  • I am deploying the azure function by calling PUT Rest call on "https://$functionAppName.scm.azurewebsites.net/api/zip/site/wwwroot" to upload a zip file (which contains run.csx, function.json and bin/*.dll files).

  • I use CloudConfigurationManager.GetSetting(settingKey) to get the appsettings in the *.dll files. I have a IsNullOrWhiteSpace check on these appsettings to throw a ConfigurationErrorsException.

Problem: After deploying, always the first trigger to the azure function fails. It fails with the ConfigurationErrorsException exception which i am throwing if a appsetting is IsNullOrWhiteSpace.
After about a minute after the first failed trigger, all the subsequent triggers start to be successful.

Is it that it takes time for appsettings to get loaded ?
Have any of you faced such issue before ? What is the workaround/solution for this ?

Answer Source

You should not be using CloudConfigurationManager in Azure App Service, as that component is designed for Cloud Services (a different Azure offering). You should avoid referencing that assembly entirely.

Instead, simply use ConfigurationManager.AppSettings["YourSetting"] to access your app settings.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download