Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamically create AppSettings in Azure function during function execution C#

I am using pre-compiled Azure Functions and I know I can read values in the App Settings using the ConfigurationManager.AppSettings["keyname"].

I have been trying to create an additional App Setting using something like the below:

var configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
var settings = configFile.AppSettings.Settings;
settings.Add(pair.Key, pair.Value);

However when I try this I get the following error message:

exePath must be specified when not running inside a stand alone exe. 

Any ideas if this is even possible? Or able to provide a pointer as how to get it working?

like image 351
Patrick McInerney Avatar asked Dec 20 '25 03:12

Patrick McInerney


1 Answers

The Azure Functions runtime configuration file is not writable, but as it runs App Service, it inherits the App Settings feature supported by it, which gives you access to manage settings that will be injected as both, application settings and environment variables at runtime through the portal.

You can manage those settings programmatically via ARM, or through the CLI.

Keep in mind that changes to those settings will trigger a site restart, so depending on your scenario, if you need settings that will be dynamically updated, you may want to consider using a different configuration/settings source, including a caching option like Redis to maintain shared state.

like image 108
Fabio Cavalcante Avatar answered Dec 23 '25 21:12

Fabio Cavalcante



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!