- Starting worker process failed, the operation has timed out : Visual studio hasn’t caught up with the function tooling yet, to overcome this issue, install the func cli and run the the command func start, if you are comfortable with VSCODE, you will be at home.
- There are lot of great articles out there on how to get started with the azure isolated host functions, but the most complete one that i found is the post Azure Functions and .NET 5: Dependency Injection – DEV Community by Kenichiro Nakamura – DEV Community
- There is no documentation out there at least from what I found on how to add configuration Ex: appsettings.json to the isolated functions project. So lets see how we can add this feature.
- Add an appsettings file to the root folder and change the file properties to copy
- Update the Program.cs class to include the following
public static void Main()
{
var host = new HostBuilder()
.ConfigureAppConfiguration(e =>
e.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true).AddEnvironmentVariables().Build()
)
.ConfigureServices(services =>
{
services.AddSingleton<DomainFacade>();
})
.ConfigureFunctionsWorkerDefaults()
.Build();
host.Run();
}
3. Update the Function with the following
public class ConfigurationTest
{
private readonly DomainFacade _domainFacade;
private readonly IConfiguration _configuration;
public ConfigurationTest(DomainFacade domainFacade, IConfiguration configuration)
{
_domainFacade = domainFacade;
_configuration = configuration;
}
[Function("ConfigurationTest")]
public async Task Run([TimerTrigger("0 */1 * * * *")] FunctionContext context)
{
var logger = context.GetLogger("Function1");
logger.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}" + _configuration["CosmosDb:AccountPrimaryKey"]);
await _domainFacade.DomainMethod(string someValue );
}
}
4. And this will work locally as well as on the cloud, without tinkering with the path of the appsettings, the example is for a timetrigger function, but this will work for any trigger.